Statalist


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

Re: st: destringing a variable?


From   "Neil Shephard" <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: destringing a variable?
Date   Wed, 12 Sep 2007 16:46:33 +0100

On 9/12/07, Ms. Marilyn Ibarra <ibarra@uga.edu> wrote:
> I need to destring a variable 'foreign_id' so I can declare a dataset to be panel as follows:
>
> xtset foreign_id year, yearly
>
> However, my variable 'foreign_id' is constructed as follows:
>
> firm      foreign_id
> 1           5011x
> 1           5011x
> 1           5011x
> 2           0017
> 2           0017
> 2           0017
> etc.
>
> I guess the solution is to get rid of the 'x' part.  Anyone know how I can easily do this so I am left with:
>
>
> firm      foreign_id
> 1           5011
> 1           5011
> 1           5011
> 2           0017
> 2           0017
> 2           0017
>
>

-man string functions- shows that you could use the -subinstr()-
function to achieve this....

gen _t = subinstr(foreign_id, "x", "", .)
drop foreign_id
rename _t foreign_id

Neil
-- 
"In mathematics you don't understand things. You just get used to
them."  - Johann von Neumann

Email - nshephard@gmail.com / n.shephard@sheffield.ac.uk
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/
*
*   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