Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: using subgroup regression coefficients in further regressions |

Date |
Thu, 19 Jul 2012 14:00:10 +0100 |

That code won't work at all. Apart from some fantasy syntax, the second time around the loop the -generate- would fail as the variable already exists. But as you want residuals, you can get them directly: gen res = . sum subgroupvar, meanonly qui forvalues i = `r(min)'/`r(max)' { reg y x1 x2 if subgroupvar==`i' predict work, residual replace res = work if subgroupvar==`i' drop work } Note, if only as a style point, that putting returned results into scalars, and then scalars into locals, is in this case two more steps than needed. On Thu, Jul 19, 2012 at 1:12 PM, Peter Hofmann <maxl@sunrise.ch> wrote: > Currently I use one regression for each subgroup of my control sample > and save the subgroup-betas. > Now I want to use the respective betas for a regression on the > treatment observations that correspond to the respective subgroup (to > extract the residuals from these regressions with the treatment > values). > > Currently I use: > . sum subgroupvar > . scalar min1=r(min) > . local j=min1 > . scalar max1=r(max) > . local k=max1 > . forvalues i=`j'(1)`k' { > . reg y x1 x2 if subgroupvar==`i' > . mat bhat = e(b) > . svmat bhat, names(bhat_`i'_) > . } > > But now I do not know how to proceed: > I want to use the respective subgroup betas in a regression on the > treatment observations (treatments are indicated by a dummy). > > I supposed it should look similar to: > . forvalues i=`j'(1)`k' { > . g yhat = `bhat_*_1' * var1 + `bhat_*_2' * var2 if subgroupvar==`i' > . } > But that results in: > . + invalid name > . r(198); > * * 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: using subgroup regression coefficients in further regressions***From:*Peter Hofmann <maxl@sunrise.ch>

- Prev by Date:
**Re: st: Re: Decomposing integers** - Next by Date:
**Re: st: Re: Decomposing integers** - Previous by thread:
**st: using subgroup regression coefficients in further regressions** - Next by thread:
**Re: Re: st: using subgroup regression coefficients in further regressions** - Index(es):