László Sándor <[email protected]>:
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 <[email protected]>:
> 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 <[email protected]> wrote:
>>
>> <>
>>
>> " sortby c: reg m2 t2"
>>
>>
>>
>> Probably -bysort-?
>>
>>
>>
>> HTH
>> Martin
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [email protected]
>> [mailto:[email protected]] Im Auftrag von Austin Nichols
>> Gesendet: Dienstag, 25. August 2009 20:37
>> An: [email protected]
>> Betreff: Re: st: AW: how to get slopes by clusters in a linear regression
>>
>> László Sándor <[email protected]>:
>> 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 <[email protected]>:
>> > 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<[email protected]>
>> wrote:
>> >> László Sándor <[email protected]>:
>> >> 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 <[email protected]>:
>> >>> 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<[email protected]>
>> wrote:
>> >>>>
>> >>>> <>
>> >>>>
>> >>>>
>> >>>> ******
>> >>>> h statsby
>> >>>> ******
>> >>>>
>> >>>>
>> >>>> HTH
>> >>>> Martin
>> >>>>
>> >>>>
>> >>>> -----Ursprüngliche Nachricht-----
>> >>>> Von: [email protected]
>> [mailto:[email protected]] Im Auftrag von László Sándor
>> >>>> Gesendet: Dienstag, 25. August 2009 17:20
>> >>>> An: [email protected]
>> >>>> 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/