Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Erik van Ingen <ejvani@hotmail.com> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: read values of tempvar instead of variable label |
Date | Fri, 4 May 2012 15:06:45 +0000 |
Dear Nick & Daniel, Thanks a lot for your comments! Indeed, the use of tempvar was unnecessary. Daniel: the levelsof / foreach solution worked (with a few changes)I hope this message doesn't get distorted... Erik ---------------------------------------- > Date: Fri, 4 May 2012 15:28:49 +0200 > Subject: Re: st: read values of tempvar instead of variable label > From: klein.daniel.81@googlemail.com > To: statalist@hsphsun2.harvard.edu > > Erik, > > I do not fully understand what you are trying to do here, but chances > are you do not need temporary variables. I will explain what your code > does, maybe this helps. Otherwise rephrase your question to clearify > what your data loojks like and what you want it to look like. > > gen newvar=. > // creates a new variable newvar with missing values for all cases > > tempvar tmpnr > gen `tmpnr'= var1 > // creates a temporary variable, named __000000 that is a copy of var1 > // note that this variable does not have a variable or value label attached > > replace newvar=1 if othervar`tmpnr'==1 > // this does not work, because there is no variable named > othervar__000000 in your dataset > // I do not see what you are trying to do here, but others may have an idea > > Do you want something like > > g newvar = . > qui levelsof var1 ,l(lvls) > foreach l of loc lvls { > qui replace newvar = `x' if (othervar`x' == 1) > } > > Best > Daniel > > -- > 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. > * > * 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/ * * 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/