<>
Put the string in quotation marks
*************
clear*
input str10 country
Argentina
Aruba
Australia
Austria
Bahrain
end
compress
gen revenue=90
replace revenue=100 if country=="Australia"
list, noobs
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Mike Kim
Gesendet: Mittwoch, 22. April 2009 18:05
An: [email protected]
Betreff: st: How to change value based on string variable?
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/
*
* 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/