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]

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


From   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: read values of tempvar instead of variable label
Date   Fri, 4 May 2012 15:28:49 +0200

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index