Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Split string variable


From   Suryadipta Roy <sroy2138@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Split string variable
Date   Mon, 22 Oct 2012 07:54:14 -0400

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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index