我在R
中使用lfe
包進行高維固定效果。試圖在沒有協變量的情況下運行時遇到麻煩。也就是說,只有固定的效果。我的代碼是:R中的四部分公式語法
library(lfe)
data=read.csv("path_to//my_data.csv")
y <- cbind(col1)
x <- cbind(col2)
est <- felm(y ~ 0|x, data)
然而,最後一行給出了錯誤:
Error in model.frame.default(terms(formula, lhs = lhs, rhs = rhs, data = data, :
variable lengths differ (found for 'x')
請注意,我用正確的語法調用它,根據四部分組成的配方格式,可以看出在documentation
第20頁,在那裏說:
The formula specification is a response variable followed by a four part formula. The first part consists of ordinary covariates, the second part consists of factors to be projected out. The third part is an IV-specification. The fourth part is a cluster specification for the standard errors. I.e. something like
y ~ x1 + x2 | f1 + f2 | (Q|W ~ x3+x4) | clu1 + clu2
wherey
is the response,x1,x2
are ordinary covariates,f1,f2
are factors to be projected out,Q
andW
are covariates which are instrumented byx3
andx4
, andclu1,clu2
are factors to be used for computing cluster robust standard errors. Parts that are not used should be specified as0
, except if it’s at the end of the formula, where they can be omitted.
一個無關點,使用'attach'是一個壞主意。我幾乎肯定'felm'有一個'data'參數。改用它。你應該可以把它寫成'est < - felm(col1〜0 | col2,data = data)'。 – lmo