Eric Uslaner wrote:
I have a string variable problem and I have looked high and low in the
manual for a solution. One variable in a data set is composed of both
the name of a country and the year of a survey, such as:
Albania2002
Albania2005
Serbia&Montenegro2002
Serbia&Montenegro2005
I want to drop the last four digits (there is already a variable called
year). I figured out how to drop the last four digits into another
variable with substr but cannot figure out what to do to keep the
country names (which vary in length) and drop the year.
------------------------------------------
The -length()- function gives the number of characters, and then
it is not that difficult:
clear
input str25 namenum
"Albania2002"
"Albania2005"
"Serbia&Montenegro2002"
"Serbia&Montenegro2005"
end
gen len = length(namenum)
gen name = substr(namenum,1,len-4)
gen num = substr(namenum,len-3,.)
Hope this helps
Svend
________________________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: [email protected]
_________________________________________________________
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/