Statalist


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

st: How to change value based on string variable?


From   Mike Kim <raravise@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: How to change value based on string variable?
Date   Wed, 22 Apr 2009 11:04:39 -0500

Hi all,

My data include 50 countries. Sometimes I need to change some values in 
another variable based on country name. If I leave country names as string, 
the following does not work, for example.

replace revenue=100 if country==Australia

So, I usually change country names into numeric using "encode."

 label list country
           1 Argentina
           2 Aruba
           3 Australia
           4 Austria
           5 Bahrain
.......

Then, I use the following code:

replace revenue=100 if country==3

However, if I drop or add some contries later Australia is no longer 3 and I 
have to go through my do file to correct every possible mistake which is 
frustrating. Is there any better way to do this job so that I can reduce 
errors in data management?

Thank you in advance.
Mike. 

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