[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Austin Nichols <austinnichols@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: AW: how to get slopes by clusters in a linear regression |

Date |
Thu, 27 Aug 2009 10:06:59 -0400 |

László Sándor <sandorl@gmail.com>: I'll try one more time--your code does not produce the estimates you said you wanted. See the example I already provided. 2009/8/26 László Sándor <sandorl@gmail.com>: > Yes, Martin, thanks for catching this. > > Since then, I have been successful with the statsby verion, this works > as intended. Now the code runs through several dependent variables and > does the regression cluster by cluster, which are identified by > taxproid07 in my case, and also fits a kernel density graph to them. > (Please let me omit code setting up the data. The code could be > instructional without that too.) > > reg treat `controls' > predict treat_fwl, resid > > foreach v of varlist d_fdeic midinc08 poor08 highinc08 d_eic_wage midwage08 { > > reg `v' `controls' > predict `v'_fwl, resid > > statsby effect_on_`v'=_b[treat_fwl], by(taxproid07) > saving(effect_on_`v', replace): reg `v'_fwl treat_fwl > > merge m:1 taxproid07 using effect_on_`v' > > kdensity effect_on_`v' > > graph save indiveffect_on_`v', replace > graph export indiveffect_on_`v'.eps, replace > > drop _mer* > } > > Best, > > Laszlo > On Tue, Aug 25, 2009 at 3:33 PM, Martin Weiss <martin.weiss1@gmx.de> wrote: >> >> <> >> >> " sortby c: reg m2 t2" >> >> >> >> Probably -bysort-? >> >> >> >> HTH >> Martin >> >> -----Ursprüngliche Nachricht----- >> Von: owner-statalist@hsphsun2.harvard.edu >> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Austin Nichols >> Gesendet: Dienstag, 25. August 2009 20:37 >> An: statalist@hsphsun2.harvard.edu >> Betreff: Re: st: AW: how to get slopes by clusters in a linear regression >> >> László Sándor <sandorl@gmail.com>: >> Your code does not run as written, and the approach you outline does >> not do what you want (unless I am misunderstanding your problem): >> >> webuse grunfeld, clear >> set seed 1 >> ren company c >> keep if c<5 >> qui ta c, g(d_) >> g byte t=uniform()>.5 >> forv i=1/4 { >> g byte td_`i'=d_`i'*t >> } >> drop d_1 >> reg mvalue kstock d_* td_* >> g good=. >> forv i=1/4 { >> replace good=_b[td_`i'] if c==`i' >> } >> g bad=. >> qui reg mvalue kstock >> predict m2, res >> qui reg t kstock >> predict t2, res >> forv i=1/4 { >> qui reg m2 t2 if c==`i' >> replace bad=_b[t2] if c==`i' >> } >> tabdisp c, c(good bad) >> >> Again: Make sure you are getting the right answer in a small subsample >> before you go too far... >> >> 2009/8/25 László Sándor <sandorl@gmail.com>: >> > Austin, >> > thanks for the code. I meant the latter approach, or even simpler, as >> > you don't need interactions if you will estimate it cluster by >> > cluster. >> > >> > In your code (without collecting the coefficients): >> > >> > qui reg mvalue kstock >> > predict m2, res >> > qui reg t kstock >> > predict t2, res >> > sortby c: reg m2 t2 >> > >> > The last can be made more useful with statsby, as Martin suggested. >> > >> > Thanks, >> > >> > Laszlo >> > >> > >> > On Tue, Aug 25, 2009 at 1:31 PM, Austin Nichols<austinnichols@gmail.com> >> wrote: >> >> László Sándor <sandorl@gmail.com>: >> >> Using the FWL thm is the fastest way to go, probably, but I am not >> >> clear on what you are actually doing. Is it something like one of the >> >> approaches below? Or are you trying to get the individual-specific >> >> coefs on the treatment dummy (harder, but can be done in Mata without >> >> making any really big matrices)? >> >> >> >> webuse grunfeld, clear >> >> set seed 1 >> >> ren company c >> >> keep if c<5 >> >> qui ta c, g(d_) >> >> g byte t=uniform()>.5 >> >> forv i=1/4 { >> >> g byte td_`i'=d_`i'*t >> >> } >> >> drop d_1 >> >> reg mvalue kstock d_* td_* >> >> est sto reg1 >> >> egen double m1=mean(mvalue), by(c t) >> >> g double mres=mvalue-m1 >> >> egen double k1=mean(kstock), by(c t) >> >> g double kres=kstock-k1 >> >> areg mres kres, a(c) >> >> est sto reg2 >> >> egen c2=group(t c) >> >> areg mvalue kstock, a(c2) >> >> est sto reg3 >> >> est table reg? >> >> >> >> Or are you doing something like: >> >> >> >> qui reg mvalue td_2 td_3 td_4 d_* kstock >> >> predict m2, res >> >> qui reg td_1 td_2 td_3 td_4 d_* kstock >> >> predict t2, res >> >> reg m2 t2 >> >> >> >> which still needs big matrices as the problem gets big? Make sure you >> >> are getting the right answer in a small subsample before you go too >> >> far... >> >> >> >> 2009/8/25 László Sándor <sandorl@gmail.com>: >> >>> Thank you, Martin! >> >>> >> >>> I don't see how this could be used to estimate the model in a single >> >>> command -- statsby still seem to break down the regression by >> >>> clusters, without the intercluster restrictions on the >> >>> controls/covariates. >> >>> >> >>> However, this led me to try to apply the Frisch-Waugh-Lowell theorem: >> >>> I estimate the univariate regression of outcome on treatment by each >> >>> cluster, I must only use the residuals for both after regressing them >> >>> on the set of controls. >> >>> >> >>> If there is no other way, this seems to be doable. >> >>> >> >>> Thanks again! >> >>> >> >>> Laszlo >> >>> >> >>> On Tue, Aug 25, 2009 at 11:23 AM, Martin Weiss<martin.weiss1@gmx.de> >> wrote: >> >>>> >> >>>> <> >> >>>> >> >>>> >> >>>> ****** >> >>>> h statsby >> >>>> ****** >> >>>> >> >>>> >> >>>> HTH >> >>>> Martin >> >>>> >> >>>> >> >>>> -----Ursprüngliche Nachricht----- >> >>>> Von: owner-statalist@hsphsun2.harvard.edu >> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von László Sándor >> >>>> Gesendet: Dienstag, 25. August 2009 17:20 >> >>>> An: statalist@hsphsun2.harvard.edu >> >>>> Betreff: st: how to get slopes by clusters in a linear regression >> >>>> >> >>>> Dear Fellow Statalisters, >> >>>> >> >>>> I want to extend a fixed-effects-type model to allow for different >> >>>> coefficients on a variable (actually a treatment dummy) by each >> >>>> cluster I have. The richness of my data would allow for that. However, >> >>>> I did not find a way to do it in Stata that would report (and collect) >> >>>> the coefficients themselves. -xtmixed- doesn't seem to do so. I would >> >>>> like to restrict the coefficients on controls to be equal across >> >>>> clusters, so estimation by cluster is not a solution either. >> >>>> >> >>>> If there were a way that could collect the slopes to a single new >> >>>> variable (with the same value for observations in the same cluster, >> >>>> naturally), that would be the best. It would be great if I did not >> >>>> need to introduce all the 1438 cluster-indicator variables and >> >>>> interactions myself, and collect the coefficients. >> >>>> >> >>>> Thank you for any guidance in advance! >> >>>> >> >>>> Laszlo * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: how to get slopes by clusters in a linear regression***From:*László Sándor <sandorl@gmail.com>

**Re: st: AW: how to get slopes by clusters in a linear regression***From:*László Sándor <sandorl@gmail.com>

**Re: st: AW: how to get slopes by clusters in a linear regression***From:*Austin Nichols <austinnichols@gmail.com>

**Re: st: AW: how to get slopes by clusters in a linear regression***From:*László Sándor <sandorl@gmail.com>

**Re: st: AW: how to get slopes by clusters in a linear regression***From:*Austin Nichols <austinnichols@gmail.com>

**Re: st: AW: how to get slopes by clusters in a linear regression***From:*László Sándor <sandorl@gmail.com>

- Prev by Date:
**Re: st: Missing values** - Next by Date:
**Re: st: xtivreg2 Random Effects and Durbin Wu Hausman** - Previous by thread:
**Re: st: AW: how to get slopes by clusters in a linear regression** - Next by thread:
**st: Hausman test probability is 1 after xtreg** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |