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: Split string variable


From   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: Split string variable
Date   Mon, 22 Oct 2012 14:24:29 +0200

Your -foreach- loop will not work for various reasons, but I will not
comment on that. You are looking for

g foo = substr(ccodealp_year, 1, 3)

Best
Daniel

-- 
Dear Statalisters,
I have the following problem that probably needs some intelligent
application of -substr- and/or -trim- , but that I have not been able
to achieve so far. I have a string variable (name "ccodealp_year")
that takes the following observations:
AFG46
AFG47
...
...
VDR09
VDR10

Each observation is a three-digit country code followed by two-digit
year. I need to create a variable consisting of just the three-digit
country codes, i.e. need to remove the two-digit years from each
observation of the string variable. I have also tried something like:
foreach w of varlist ccodealp_year { gen `ccodealp' =
"`ccodealp_year'-`year'" }, obviously without success. I was wondering
if anyone can point me to the right direction. Any help is greatly
appreciated.

Best regards.
Suryadipta.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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