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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: using arrays to make multiple indicator variables


From   Beth Fussell <befeff@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: using arrays to make multiple indicator variables
Date   Fri, 12 Mar 2010 09:51:01 -0800

Hi! I'm a new Stata user trying to convert my SAS programs. I've followed
the model Gouldner provides on using SAS-like arrays but it isn't working.
I'm not getting any useful error messages either. Can someone identify the
problem in my code?

Thanks!


/* create indicators of membership by type */
gen memchurh_r=.
gen memfrat_r=.
gen memserv_r=.
gen memvet_r=.
gen mempolit_r=.
gen memunion_r=.
gen memsport_r=.
gen memyouth_r=.
gen memschl_r=.
gen memhobby_r=.
gen memgreek_r=.
gen memnat_r=.
gen memfarm_r=.
gen memlit_r=.
gen memprof_r=.
gen memother_r=.
gen meminfgr_r=.

local array1 "memchurh_r memfrat_r memserv_r memvet_r mempolit_r memunion_r
memsport_r memyouth_r memschl_r memhobby_r memgreek_r memnat_r memfarm_r
memlit_r memprof_r memother_r meminfgr_r"
local array2 "memchurh memfrat memserv memvet mempolit memunion memsport
memyouth memschl memhobby memgreek memnat memfarm memlit memprof memother
meminfgr"
local i = 1
local n : word count `array1'
di `n'
local o : word count `array2'
di `o'
di `i'
while `i' == `n' {
    local var1 : word `i' of `array1'
    local var2 : word `i' of `array2'
    replace `var1' = 1 if `var2' == 1
    replace `var1' = 0 if `var2' == 2
    local i = `i' + 1
}

*
*   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   |   Site index