Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: loop within a loop


From   Ryan Stevens <stevrl7@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: loop within a loop
Date   Tue, 30 Apr 2013 11:25:57 -0400

Adam,

A loop is not necessary for this. You could either i. generate new
dummies using 'tab group, gen(ethnicity)' and then rename the
variables or ii. generate dummies by combining generate and
conditionals. I'm going with ii. here:

gen white = (eth == 1)
gen black = (eth == 2)
gen hispanic = (eth==3)
gen asian = (eth == 4)
gen mixed = (eth==5)

Best,
Ryan

On Tue, Apr 30, 2013 at 11:20 AM, Adam Guerrero <adamgue@gmail.com> wrote:
> Hello,
>
> I am trying to create a loop within a loop for the following block of
> code (loop through variables white, black, hispanic, asian, and mixed
> from values 1 to 5):
>
> generate white=0
> replace white=1 if eth==1
> generate black=0
> replace black=1 if eth==2
> generate hispanic=0
> replace hispanic=1 if eth==3
> generate asian=0
> replace asian=1 if eth==4
> generate mixed=0
> replace mixed=1 if eth==5
>
> I know decode would be easier, but please consider responding to help
> me out learning how to loop.
>
> I'm relatively new to Stata, so any suggestions would be very much appreciated.
>
> Thank you in advance,
>
> Adam Guerrero
>
> --
> Adam A. Guerrero
> Skype: adamadam3741
> Phone: 214-274-3776
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index