据我所知,Stata和R都有"预测"功能.我试图复制使用R在Stata中执行的结果,结果涉及计算预测值的标准偏差.R中是否有功能,可能使用其"预测"功能,这将允许我这样做?我似乎无法完美地复制结果.如果它有帮助,Stata代码执行以下操作:
reg Y X1 X2 if condition
predict resid, r
predict stdf, stdf
Run Code Online (Sandbox Code Playgroud)
stdf论证的定义是:
stdf计算预测的标准误差,这是1次观测的点预测的标准误差.它通常被称为未来或预测值的标准误差.通过构造,产生的标准误差stdf总是大于由此产生的误差stdp; 参见[R]预测中的方法和公式
我写的R代码是:
fit <- lm(Y ~ X1 + X2, data=df)
new.df <- data.frame(...) # This is a new data frame with my new data period I want to predict in
predict(fit, new.df, se.fit = TRUE)
Run Code Online (Sandbox Code Playgroud)
但是,当我将标准误差转换为标准偏差时,它们与Stata输出不匹配.
提前致谢!
我正在写python中的csv,我想知道为什么我的输出文件在程序完成运行时是空白的.首先,这是我的代码:
reader = csv.reader(open(location, 'rU'), delimiter = ',', quotechar = '"')
writer = csv.writer(open('temp.csv', 'wb'), delimiter = ',', quotechar = '"')
writer.writerow(["test", "test", "test", "test", "test", "test", "test"])
count = 0
for row in reader:
if count != 0 and count < len(split):
writer.writerow([row[0], row[1], row[2], row[3], row[4], row[5], split[count-1]])
count = count + 1
Run Code Online (Sandbox Code Playgroud)
我知道一些事情:
在此先感谢您的帮助!
编辑:这是我正在使用的一些更新代码:
infile = open(location, 'rU')
outfile = open('temp.csv', 'wb')
reader = csv.reader(infile, delimiter = ',', quotechar = '"')
writer = …Run Code Online (Sandbox Code Playgroud)