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: How to apply a command to numeric variables only


From   "Paul O'Brien" <[email protected]>
To   statalist <[email protected]>
Subject   st: How to apply a command to numeric variables only
Date   Tue, 29 May 2012 06:28:42 +0100

I want to do a foreach command to convert numeric variables to string before a merge. Only some of the variables are numeric and which ones varies with each database.

foreach var of varlist srhcareactivity1-srhcareactivity6{
	decode `var', generate(string)
	drop `var'
	rename string `var'
}

Error message: not possible with string variable. 

I have tried using capture to ignore the error.

How can I restrict the command to numeric variables only?

By the way, is there a way to keep the variable label which is lost when I use generate.

Thanks,

Paul










*
*   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