Statalist The Stata Listserver


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

Re: st: RE: generating new vars from old by cutting off a portion off the old


From   mfeurey@weber.ucsd.edu
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: generating new vars from old by cutting off a portion off the old
Date   Sun, 13 May 2007 23:13:41 -0700 (PDT)

That worked beautifully, thank you.  Just saved me five hours of banging
my head against the wall.

Melanie

> Try
>
> gen str State = substr(oldvar,4,2)
>
> This assumes that your original variable was string.
>
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of
> mfeurey@weber.ucsd.edu
> Sent: Monday, 14 May 2007 14:06
> To: statalist@hsphsun2.harvard.edu
> Subject: st: generating new vars from old by cutting off a portion off
> the old
>
> Hi,
>
> I have a variable that has about 8 characters per observation and I need
> to take 2 characters (4th and 5th characters) and generate them as new
> variables representing state codes.  So for example, the variable has as
> one of its value CITNA134.  The characters I need to extract are NA,
> which
> will be recoded as State code.  How would I go about doing 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/
>
> *
> *   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/
>


*
*   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