To create the counter variable you could use -egen, group-
egen id = group(cotnum)
Or, rather than creating a new variable you could use -levelsof- and -
foreach-
levelsof cotnum, local(levels)
foreach l of local levels {
regress var if cotnum == `l'
.....
}
Or, the problem of collecting the estimated coefficients, standard
errors, and R2 values could tackled directly using -statsby-
statsby _b _se e(r2), by(cotnum): regress .....
Hope this helps,
Scott
----- Original Message -----
From: Aamer Abu-Qarn <[email protected]>
Date: Tuesday, December 27, 2005 7:37 am
Subject: st: Replacing the content of a counter variable
> Dear All,
> I have a panel (51 obs. Per country) database of 168 countries in
> which a
> country has a code number running from 1 to 168 (the variable
> contnum). I
> dropped some of the countries that have insufficient observations
> and now
> the varable contnum has valuse like 1, 5, 11, 12, 57 and so on. I
> know that
> the number of the remaining countries is _N/51. How do I assign new
> consecutive code numbers for the remaining countries so the
> variable contnum
> looks like 1,2,3,....._N/51??? The problem is that I want to run
> countryspecific regressions for all the remaining countries and
> report _b _se R2
> for each regression. I want a loop from 1 to _N/51 but forval
> doesn't accept
> nonvalues. I created a scalar w=_N/51 but forval didn't accept
> forval x=1/w.
>
> I appreciate your help in these two issues.
>
> Aamer
>
> *
> * 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/
>
*
* 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/