2017-04-02 104 views
2

我在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 where y is the response, x1,x2 are ordinary covariates, f1,f2 are factors to be projected out, Q and W are covariates which are instrumented by x3 and x4 , and clu1,clu2 are factors to be used for computing cluster robust standard errors. Parts that are not used should be specified as 0 , except if it’s at the end of the formula, where they can be omitted.

+1

一個無關點,使用'attach'是一個壞主意。我幾乎肯定'felm'有一個'data'參數。改用它。你應該可以把它寫成'est < - felm(col1〜0 | col2,data = data)'。 – lmo

回答

0

事實證明,這是一個語法問題,通過@lmo的建議。如果我做的:

est <- felm(col1 ~ 0|col1data) 

那麼有沒有錯誤,它的工作原理