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: Generating a new var from last 11 character in a string
From
Steve Samuels <[email protected]>
To
[email protected]
Subject
Re: st: Generating a new var from last 11 character in a string
Date
Sat, 14 Dec 2013 18:05:14 -0500
************************************
input str30 bigstr
"usethesubstringcommand"
"nr 1 in some observations "
end
gen lb = length(bigstr)
gen str11 mine = substr(bigstr,lb-11,lb)
list
***********************************
Steve
On Dec 14, 2013, at 5:53 PM, lars Folkestad wrote:
Dear listers
I want to do generate a new var from the last 11 character of a string variable. I normally count the possitions that i want and use the substring command, but my oldvar has contains different number of characters. The first position of interest maybe nr 1 in some observations and number 15 in others.
Whats the best way to do this?
Lars
*
* 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/