2

I am using the lfe package for high dimenaional fixed effects in R. I am having trouble when trying to run with no covariates. That is, only with fixed effects. My code is:

library(lfe)
data=read.csv("path_to//my_data.csv")

y <- cbind(col1)
x <- cbind(col2)

est <- felm(y ~ 0|x, data)

However, the last line gives the error:

Error in model.frame.default(terms(formula, lhs = lhs, rhs = rhs, data = data,  : 
  variable lengths differ (found for 'x')

Notice that I am calling it with proper syntax, according to the four-part formula formatting, as can be seen in page 20 of the documentation, where it says:

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
splinter
  • 3,727
  • 8
  • 37
  • 82
  • 1
    One unrelated point, using `attach` is a bad idea. I'm nearly certain that `felm` has a `data` argument. Use this instead. You should be able to write this as `est <- felm(col1 ~ 0 | col2, data=data)`. – lmo Apr 02 '17 at 12:47

1 Answers1

0

It turns out that it was a syntax problem, as suggested by @lmo. If I do:

est <- felm(col1 ~ 0|col1data)

then there is no error and it works

splinter
  • 3,727
  • 8
  • 37
  • 82