Statalist


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

st: data management - string function


From   "b. water" <barleywater@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: data management - string function
Date   Wed, 24 Dec 2008 07:52:51 +0000

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®. 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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index