Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: encode question


From   "Eric A. Booth" <[email protected]>
To   [email protected]
Subject   Re: st: encode question
Date   Thu, 12 Feb 2009 14:32:50 -0600

For your variables that are numerical but Stata has stored them as string:

foreach var of varlist variables* {
	destring `var', gen(new_`var')
	drop `var'
	rename new_`var' `var'
}


If you have variables that are string and you want the variable to be numeric with strings as their labels:

foreach var of varlist variables* {
	encode `var', gen(new_`var')
	drop `var'
	rename new_`var' `var'
}

Look at the help files because you might need the 'force' or 'ignore' option depending on your data.

Eric


On Feb 12, 2009, at 2:17 PM, Arina Viseth wrote:

Dear all,

I have a dataset that I imported from Excel using insheet. However, many numerical variables (I have about 200 variables) are now showed as string variables. My question is the following: how can I transform each string variable into numerical one - and also replicate their names - without having to encode manually each one of them?

Thank you very much in advance for any help, I would very much appreciate it.

Arina

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index