For some context, see
Is there a way to tell Stata to try all values of a
particular variable in a foreach statement without specifying them?
http://www.stata.com/support/faqs/data/foreach.html
Nick
[email protected]
Scott Merryman replied to Helena Schweiger
>
> Here is oneway:
>
> egen group = group(country year)
>
> gen hlnoutput = .
> levels group, local(levels)
> foreach l of local levels {
> regress lnoutput lnl lnk lnm if group == `l'
> predict temp
> replace hlnoutput = temp if group == `l'
> drop temp
> }
>
> -levels- in conjunction with -foreach- is very useful to
> cycle through distinct
> groups.
> > My dataset has three dimensions (country, year, firm) and
> I'm estimating
> > total factor productivity (using OLS estimates as a
> reference for more
> > appropriate estimation techniques) by country and year. I
> want to get
> > the estimated values of log of output, so that I can
> calculate log of
> > TFP, but if I use predict after my regress command - which
> would look
> > for example like this:
> > sort country year;
> > by country year: regress lnoutput lnl lnk lnm;
> > predict hlnoutput, xb;
> >
> > - it uses the coefficients estimated in the last country-year pair,
> > which is not what I want. There probably is a way to do
> this (other than
> > writing down the equations for each country-year pair to get the
> > estimated values which is very time-consuming, since all the
> > coefficients need to be typed for each pair), but I cannot find it.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/