Statalist


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

Re: st: destringing a variable?


From   "Neil Shephard" <[email protected]>
To   [email protected]
Subject   Re: st: destringing a variable?
Date   Wed, 12 Sep 2007 16:46:33 +0100

On 9/12/07, Ms. Marilyn Ibarra <[email protected]> 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 - [email protected] / [email protected]
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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index