Statalist


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

Re: st: data management - string function


From   "Ashim Kapoor" <[email protected]>
To   [email protected]
Subject   Re: st: data management - string function
Date   Wed, 24 Dec 2008 14:03:38 +0530

Hello!

I think you want to do this :--

gen j=var1

gen j2=subinstr(j,"Mrs","",1)
gen  j3=subinstr(j2,"Mr","",1)
gen j4=susinstr(j3,"Ms","",1)

Note  the order of j2 and j3 , it is needed because we have Mr as as
subsitring of Mrs. It would be ruined if you did it the other way.

I hope you liked it.

Thank you,
Ashim.


On Wed, Dec 24, 2008 at 1:22 PM, b. water <[email protected]> wrote:
> dear all,
>
> stata 8.2, windows xp,
>
> i have a data management problem: have a variable (strings) of names like these:
>
> var1
> Mrs A Jones
> Mrs Anne Jones
> Ms Abra Ham
> Mr Ko Jack
> Jack Kroll
> No Probs
> Ms. Abra Ham
> Mr. Ko Jack
> . <- denotes missing
> .
> .
> Miss. Wonder Full
> Mrs Bond Trader
>
> i want to generate new variable which removed the person's title, so it appear like these:
>
> var2
> A Jones
> Anne Jones
> Abra Ham
> Ko Jack
> Jack Kroll
> No Probs
> Abra Ham
> Ko Jack
> . <- denotes missing
> .
> .
> Wonder Full
> Bond Trader
>
> i tried (thinking that i would slowly truncate Mr, Mrs, Ms title by title):
>
> gen var2=var1
> replace  var2=subinstr("Mr","Mr","",.) <- just as well i generate var2 as this command wiped out all the names!
>
> i want to also generate another variable that will assign gender based on the title of the name in var 1 i.e. if Mr or Mr. then M(ale) and if Mrs, Mrs., Ms, Ms., Miss, Miss. then F(emale). i thought generate/replace or replace/if using string functions would help but i think this require loop of a sort to achieve.
>
> F
> F
> F
> M
> .
> .
> F
> M
> .
> .
> .
> F
> F
>
> thank for advice/help.
>
> season's greetings,
> bw
>
>
>
>
>
> _________________________________________________________________
> It's the same Hotmail(R). If by "same" you mean up to 70% faster.
> http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index