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]

st: Re: problem with split command


From   "Joseph Coveney" <[email protected]>
To   <[email protected]>
Subject   st: Re: problem with split command
Date   Wed, 29 Feb 2012 12:49:34 +0900

Forgot to mention:  for this year's survey and afterward, try the alternative below.  You can use Stata's regular expressions, too.

Joseph Coveney


. input str30 state_name

                         state_name
  1. "Andhra2012"
  2. "Arunachal2012"
  3. "Assam2012"
  4. "Bihar2012"
  5. "UttarPradesh2012"
  6. end

. 
. generate byte first_numeral = indexnot(state_name, "`c(alpha)'`c(ALPHA)'")

. generate long year = real(substr(state_name, first_numeral, .))

. replace state_name = substr(state_name, 1, first_numeral - 1)
(5 real changes made)

. 
. list, noobs separator(0) abbreviate(20)

  +-------------------------------------+
  |   state_name   first_numeral   year |
  |-------------------------------------|
  |       Andhra               7   2012 |
  |    Arunachal              10   2012 |
  |        Assam               6   2012 |
  |        Bihar               6   2012 |
  | UttarPradesh              13   2012 |
  +-------------------------------------+

. 
. exit

end of do-file



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index