> sort pension
> foreach x in jub inv sob {
> by pension: gen `x'_1 = sum(`x'==1)
> by pension: gen `x'_0 = sum(`x'==0)
> by pension: replace `x'_1 = `x'_1[_N]
> by pension: replace `x'_0 = `x'_0[_N]
> }
The above can of course be shortened by using -egen-
egen `x'_1 = total(`x'==1)
egen `x'_1 = total(`x'==0)
inside the loop. Also, the random number function uniform() has been
recently renamed to runiform() in Stata 10.1. uniform() continues to
work.
Eva
*
* 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/