Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: "cond" command


From   "Eva Poen" <eva.poen@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: "cond" command
Date   Thu, 11 Sep 2008 20:19:41 +0100

> 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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index