Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: recoding question


From   Christopher Baum <kit.baum@bc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: recoding question
Date   Tue, 25 Dec 2012 13:10:17 +0000

<>
On Dec 25, 2012, at 2:33 AM, Tony wrote:

> I have a string variable with codes 
> Markedly Improved
> Markedly Worse
> Moderately Improved
> Moderately Worse
> Slightly Improved
> Slightly Worse
> Unchanged
> 
> I want to convert these to a numeric variable, but ordered in terms of improvement.  I was looking for a way to do this easily in one step, but didn't find a simple command like encode or recode.  I ended up using encode to get the variables numeric and then recoding them.  
> Is there a simple way to do this?   For seven categories it's no big deal, but if I had 20 categories and needed to do this repeatedly, it would be a pain.  
> Another option would be to prefix a numeral for the codes but that seems clumsy...

Nick Cox's Speaking Stata column in SJ 12:4, the latest issue, provides one rather nifty solution to this sort of problem...

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                             An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
  An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index