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.
Hope this helps,
Scott
----- Original Message -----
From: "Helena Schweiger" <[email protected]>
To: <[email protected]>
Sent: Sunday, March 14, 2004 6:49 PM
Subject: st: predict when using by for regress
> Hi all,
>
> 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.
> Could you please help?
>
> Thanks,
> Helena
*
* 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/