Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: data management


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: data management
Date   Sun, 25 Mar 2007 07:14:45 -0400

A more elegant solution that avoids having to perform all those replace or recodes is to create a separate dataset with two variables: id and newid:

1 3
2 5
3 8
...

You then sort that dataset by id and save as id_concord. Then in your current data set, -sort id- and -merge id using id_concord-. This technique can be used to either change ids on a one-to-one basis or map a number of ids into another scheme, such as a region grouping.


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


On Mar 25, 2007, at 2:33 AM, Suryadipta wrote:


b. Then I am trying to replace these id-s with
replace id=3 if id==1;
replace id=5 if id==2;
replace id=8 if id==3;

But the 3rd line of the command is replacing the first set
of id-s also. I would greatly appreciate if someone can
suggest how to take care of this.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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