[R] Clustered standard errors in a panel

Thomas Lumley tlumley at u.washington.edu
Thu Jul 21 16:07:01 CEST 2005


No, he wants to fit a glm() and get the right standard errors.  For linear 
models the best way to do this is to model some random effects, but doing 
so in glm changes the meanings of the parameters.  To estimate the same 
parameters you want to use the sandwich standard errors variously 
attributed to Huber and White.

The Design package has robcov() to do this, and there is also code at
http://faculty.washington.edu/tlumley/data2001/sandwich.R

 	-thomas


On Wed, 20 Jul 2005, Spencer Graves wrote:

> 	  Have you considered "lmer" in library(lme4)?  If you are interested
> in this, you may want to check the article by Doug Bates in the latest R
> news, www.r-project.org -> Documentation:  Newsletter.
>
> 	  spencer graves
>
> Thomas Davidoff wrote:
>
>> I want to do the following:
>>
>> glm(y ~ x1 + x2 +...)
>> within a panel.  Hence y, x1, and x2 all vary at the individual
>> level.  However, there is likely correlation of these variables
>> within an individual, so standard errors need adjustment.
>> I do not want to estimate fixed effects, but do want to cluster
>> standard errors at the individual level.
>> Is there an automated way to do this?  Nothing in the cluster
>> documentation makes it clear that there is.
>>
>> (An alternative is to do this by hand.  In that case, I would need to
>> be able to calculate weighted sums of x1 and x2... at the individual
>> level.  I can do this at the variable level [with lapply,split and
>> unsplit], but would love to be able to do so over the matrix of x's.
>> Of course, doing by hand is less easy than an automated solution if
>> it exists.)
>>
>>
>> Thomas Davidoff
>> Assistant Professor
>> Haas School of Business
>> UC Berkeley
>> Berkeley, CA 94720
>> phone:     (510) 643-1425
>> fax:        (510) 643-7357
>> davidoff at haas.berkeley.edu
>> http://faculty.haas.berkeley.edu/davidoff
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> -- 
> Spencer Graves, PhD
> Senior Development Engineer
> PDF Solutions, Inc.
> 333 West San Carlos Street Suite 700
> San Jose, CA 95110, USA
>
> spencer.graves at pdf.com
> www.pdf.com <http://www.pdf.com>
> Tel:  408-938-4420
> Fax: 408-280-7915
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list