2017-04-02 2 views
2

Ich verwende das lfe Paket für hohe maintensioned feste Effekte in R. Ich habe Probleme, wenn ich versuche, ohne Kovariaten zu laufen. Das heißt, nur mit festen Effekten. Mein Code ist:Vierteilige Formel-Syntax in R

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

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

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

jedoch die letzte Zeile gibt den Fehler:

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

Beachten Sie, dass ich es mit der richtigen Syntax nenne, nach der vierteiligen Formel Formatierung, wie man sehen kann in Seite 20 des documentation, wo es heißt:

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

Ein unabhängiger Stelle mit 'attach' eine schlechte Idee ist. Ich bin mir fast sicher, dass 'felm' ein' data' Argument hat. Benutze das stattdessen. Sie sollten dies als 'est <- felm (col1 ~ 0 | col2, data = data) schreiben können. – lmo

Antwort

0

es stellt sich heraus, dass es ein Syntax Problem war, wie von @lmo vorgeschlagen. Wenn ich das tue:

est <- felm(col1 ~ 0|col1data) 

dann gibt es keine Fehler und es funktioniert