Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: documentation of old -for- syntax


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: documentation of old -for- syntax
Date   Fri, 18 Apr 2014 18:33:57 +0100

For some discussion, see
http://www.stata-journal.com/sjpdf.html?articlenum=pr0009

The first may be translated

gen byte child18=0

forval j = 1/18 {
     bysort serial year: egen temp1=count(pernum) if  (momloc==`j' |
poploc==`j') & age<=18
    bysort serial year: egen temp2=max(temp1)
    replace child18=temp2 if pernum==`j'
    drop temp*
}

Actually, that could be

gen byte child18=0

forval j = 1/18 {
     bysort serial year: egen temp = count(pernum / ((momloc==`j' |
poploc==`j') & age<=18))
    replace child18 = temp if pernum==`j'
    drop temp
}

The second is processing parallel lists. More discussion in the article cited.

Nick
[email protected]


On 18 April 2014 17:30, László Sándor <[email protected]> wrote:
> Hi,
>
> I am not aware of documentation on some syntax I found in another
> researcher's public code base. It still runs on Stata 13.1 MP (for
> mac, e.g.), but I would feel better if I could double check what is
> going on. Could anyone guide me to some readings on code like the
> lines below? (-help for- says that "for is an out-of-date command as
> of Stata 8.  See foreach and forvalues for its replacement.")
>
> gen byte child18=0
> for num 1/18: bysort serial year: egen temp1=count(pernum) if
> (momloc==X | poploc==X) & age<=18 \ bysort serial year: egen
> temp2=max(temp1) \ replace child18=temp2 if pernum==X \ drop temp*
>
> or:
>
> gen stcode=""
> for @ in any AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS KY LA
> MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD
> TN TX UT VA VT WA WI WV WY \ # in num 02 01 05 04 06 08 09 11 10 12 13
> 15 19 16 17 18 20 21 22 25 24 23 26 27 29 28 30 37 38 31 33 34 35 32
> 36 39 40 41 42 44 45 46 47 48 49 51 50 53 55 54 56: replace stcode="@"
> if statefip==#
>
> or:
>
> gen generosity=.
> for Y in num 1984/2002 \ A in num 0.578 0.598 0.609 0.631 0.658 0.689
> 0.727 0.757 0.780 0.803 0.824 0.847 0.872 0.892 0.906 0.926 0.957
> 0.984 1.000 \ D in num 500 550 550 851 874 910 953 1192 1324 1434 2038
> 2094 2152 2210 2271 2312 2353 2428 2506: replace
> generosity=ln(.4*((D*(1+eitc_s_child1))/A)+.4*((D*(1+eitc_s_child2))/A)+.2*((D*(1+eitc_s_child3))/A))
> if year==Y
>
> Thanks,
>
> Laszlo
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index