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]

st: RE: read values of tempvar instead of variable label


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: read values of tempvar instead of variable label
Date   Fri, 4 May 2012 14:31:40 +0100

At the simplest you may just be after 

replace newvar = 1 if var1 == 1 


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

code below is mangled, not just as it arrives in my inbox but also in the Harvard and StataCorp versions of the archives. My best guess is that you wrote (I'll doublespace to ensure that it doesn't happen again) 

gen newvar=.  

tempvar tmpnr

gen `tmpnr'= var1    // var1 is in my data and ranges from 1 to 12

replace newvar=1 if othervar`tmpnr'==1    // othervar1 to othervar12 are also in my data (dummy vars)

You are confusing variable names and variable values in various ways. (Also, variable labels are quite different in Stata and appear nowhere in this problem.) 

I don't understand what your aim is either. I imagine that you want to cycle somehow over the -othervar*-, for which a basic construct is 

forval j = 1/12 { 
	<something to do with -othervar`j'-> 
}

If that doesn't help, or someone else doesn't solve your problem, I'd advise a word and example description of what your set-up is and what you want. 

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

Erik van Ingen

Dear all, Sorry to ask such a newbie question, but I can't find the answer elsewhere. Can anyone please tell me how to get the code below to work? I am trying to use tempvar in order to use the value of a variable to address another variable. I get the error message "othervar__000000 not found": Stata replaces the local with the variable label of "tmpnr" instead of its value (for each case in the data). Any help would be much appreciated. Best,Erik van Ingen.

gen newvar=.tempvar tmpnrgen `tmpnr'= var1    // var1 is in my data and ranges from 1 to 12replace newvar=1 if othervar`tmpnr'==1    // othervar1 to othervar12 are also in my data (dummy vars)


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index