whoknows
whoknows

Reputation: 73

how can i specify the cluster in the regression model with felm() function

how can I specify the cluster in the regression model with felm() function: I have been trying and trying but I can't make it work. Does anyone know what is wrong with my code? This is the code I have been trying to use.

newreg <- felm(log(Price2) ~ Detached.house + Semi.detached.house + Attached.houses - Apartment +
  Stock.apartment + Housing.cooperative - Sole.owner + Age +
  BRA + Bedrooms + Balcony + Lotsize + Sentrum + Alna + Vestre.Aker + Nordstrand + Marka +  
  Ullern + Østensjø + Søndre.Nordstrand + Stovner + Nordre.Aker + Bjerke + 
  Grorud + Gamle.Oslo + St..Hanshaugen + Grünerløkka + Sagene - Frogner|0|0|, data=Data)

what I am trying to do is automatically produced the clustered standard errors in stargazer with the felm() function.

Upvotes: 0

Views: 672

Answers (1)

DaveArmstrong
DaveArmstrong

Reputation: 21937

The help file 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.

So, I would imagine it would be something like:

newreg <- felm(log(Price2) ~ Detached.house + Semi.detached.house + Attached.houses - Apartment +
  Stock.apartment + Housing.cooperative - Sole.owner + Age +
  BRA + Bedrooms + Balcony + Lotsize + Sentrum + Alna + Vestre.Aker + Nordstrand + Marka +  
  Ullern + Østensjø + Søndre.Nordstrand + Stovner + Nordre.Aker + Bjerke + 
  Grorud + Gamle.Oslo + St..Hanshaugen + Grünerløkka + Sagene - Frogner|0|0|cluster_var, data=Data)

where cluster_var is the name of the variable you want to cluster on. Without the data, I can't test it, though.

Upvotes: 2

Related Questions