Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Help with arrays


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Help with arrays
Date   Tue, 23 Mar 2004 12:54:57 -0000

When you refer to a local macro, the opening 
quote differs from the closing quote. Use ` not '. 

Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of 
> Joseph McCrary
> Sent: 23 March 2004 04:08
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Help with arrays
> 
> 
> array that will recode a variable into one of four values based on the
> combined values of two other variables. I've got to do this over 40
> variables across four domains. Here is the code I am using 
> for the first
> domain:
> 
>        gen dom1t1=0
>        gen dom1t2=0
>        gen dom1t3=0
>        gen dom1t4=0
>        gen dom1t5=0
>        gen dom1t6=0
>        gen dom1t7=0
>        local read "dom1t1 dom1t2 dom1t3 dom1t4 dom1t5 dom1t6 dom1t7"
>        local able "able5 able10 able15 able20 able25 able30 able34"
>        local willing "willing5 willing10 willing15 willing20 willing25
> willing30 willing34"
>        local i = 1
>        local n: word count 'read'
>        while 'i' <= 'n' {
>          local var1: word 'i' of 'read'
>          local var2: word 'i' of 'able'
>          local var3: word 'i' of 'willing'
>          recode 'var1' 0=1 if (('var2'>0 & 'var2'<4) & ('var3'>0 &
> 'var3'<4))
>          recode 'var1' 0=2 if (('var2'>0 & 'var2'<4) & ('var3'>3 &
> 'var3'<6))
>          recode 'var1' 0=3 if (('var2'>3 & 'var2'<6) & ('var3'>0 &
> 'var3'<4))
>          recode 'var1' 0=4 if (('var2'>3 & 'var2'<6) & ('var3'>3 &
> 'var3'<6))
>          local i = 'i' + 1
>        }
> 
>        But when I run the code as a do file I get the following error
> message:
> 
> 
>        . local read "dom1t1 dom1t2 dom1t3 dom1t4 dom1t5 dom1t6 dom1t7"
> 
>        . local able "able5 able10 able15 able20 able25 able30 able34"
> 
>        . local willing "willing5 willing10 willing15 
> willing20 willing25
> willing30 willing34"
> 
>        . local i = 1
> 
>        . local n: word count 'read'
> 
>        . while 'i' <= 'n' {
>          2.   local var1: word 'i' of 'read'
>          3.   local var2: word 'i' of 'able'
>          4.   local var3: word 'i' of 'willing'
>          5.   recode 'var1' 0=1 if (('var2'>0 & 'var2'<4) & 
> ('var3'>0 &
> 'var3'<4))
>          6.   recode 'var1' 0=2 if (('var2'>0 & 'var2'<4) & 
> ('var3'>3 &
> 'var3'<6))
>          7.   recode 'var1' 0=3 if (('var2'>3 & 'var2'<6) & 
> ('var3'>0 &
> 'var3'<4))
>          8.   recode 'var1' 0=4 if (('var2'>3 & 'var2'<6) & 
> ('var3'>3 &
> 'var3'<6))
>          9.   local i = 'i' + 1
>         10. }
>        'i' invalid name
>        r(198);
> 
>        Why is it telling me that 'i' is an invalid name. I'm 
> relying on Bill
> Gould's explanation on using SAS-like arrays from
> http://www.stata.com/support/faqs/data/arrays.html
> 
>        Thanks.
> 
>        Joseph McCrary
>        203 East 32nd St.
>        Baltimore, MD 21218
>        (443) 527-6290 (ph)
>        (443) 267-0151 (fax)
> 
> 
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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