Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: RE: left right string


From   "Lachenbruch, Peter" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: RE: left right string
Date   Wed, 19 May 2010 08:04:38 -0700

Two compliments: 
First to Tyler for posing an interesting problem (and one I have faced) and second to Martin for posting a very nice solution (that I hadn't figured out).
Well done Both!

Tony

Peter A. Lachenbruch
Department of Public Health
Oregon State University
Corvallis, OR 97330
Phone: 541-737-3832
FAX: 541-737-4001


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Martin Weiss
Sent: Tuesday, May 18, 2010 2:24 PM
To: [email protected]
Subject: RE: st: RE: RE: left right string


<>

" I just realized my ranges are labels"



No big deal, just -decode- the thing beforehand:


***********
clear*

set obs 3
gen byte hhh_age=_n

la def ages 1 "15-19" 2 "20-24" 3 "25-39" 
la val hhh_age ages

decode hhh_age, gen(newhhh_age)

split newhhh_age, gen(age) parse(-) destring
rename age1 age_min
rename age2 age_max

list, noo
***********


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Tyler Frazier
Sent: Dienstag, 18. Mai 2010 23:17
To: [email protected]
Subject: Re: st: RE: RE: left right string

I just realized my ranges are labels

On Tue, May 18, 2010 at 11:08 PM, Martin Weiss <[email protected]> wrote:
>
> <>
>
>
> You can generate the new variables and -destring- (which I assume you also
> want) in one fell swoop:
>
>
> ***********
> clear*
>
> inp str5 hhh_age
> 15-19
> 20-24
> 25-39
> end
>
> split hhh_age, gen(age) parse(-) destring
> rename age1 age_min
> rename age2 age_max
>
> list, noo
> ***********
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Martin Weiss
> Sent: Dienstag, 18. Mai 2010 23:05
> To: [email protected]
> Subject: st: RE: left right string
>
>
> <>
>
> Have you had a look at -split-?
>
>
> HTH
> Martin
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Tyler Frazier
> Sent: Dienstag, 18. Mai 2010 23:03
> To: [email protected]
> Subject: st: left right string
>
> simple question, I hope -- I have a variable which is a range of ages,
> for example  the variable name is hhh_age and the quantities are
> 15-19, 20-24, 25-39 etc...
>
> and I want to generate a new variable (age_min) that returns the left
> two characters from hhh_age , and another variable that generates the
> right two -- (age_max)
>
> I searched but couldnt find it, seems like a very simple thing, but
> cant figure it out.
>
> any help is greatly appreciated
>
> Ty
> *
> *   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/
>
> *
> *   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/


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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index