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: Setting a variable's value equal to the name of another variable


From   Nima Darbari <[email protected]>
To   [email protected]
Subject   st: Setting a variable's value equal to the name of another variable
Date   Fri, 29 Nov 2013 15:21:10 +0100

Dear all
I have written the simple code below to set the value of a variable
equal to the name of another variable if some conditions are met, but
I keep receiving 'type mismatch' error. As you see the variables names
are consisted of 'Listedness' and numbers from 1 to 371. I changed
type of the 'IPO' variables which contains 0 or 1 originally, to
string, but it didn't help.



foreach var of varlist Listedness1-Listedness371{
forvalues d=1/`=_N'{
if `var'[`d'] ==1 & `var'[`d'-1]==0 & IPO[`d']==1 & IPO[`d'-1]==0{
replace IPO="`var'" in `d'
}
}
}
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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