Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: parsing a variable positionally


From   Svend Juul <SJ@SOCI.AU.DK>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: parsing a variable positionally
Date   Tue, 3 Jun 2008 11:52:04 +0200

Rufus wrote:

I'm trying to convert a variable into a date. Ordinarily, this would be
simple using Stata's date() functions, but one of my variables contains
both month and date (i.e. 403 is April 3rd), while another contains
year. I'm trying to split the month+date variable into two variables by
parsing after the first character. I tried converting the variable to a
string and using the "split" command, but it does not allow me to parse
positionally; it merely allows me to specify a parsing character. Is
there a way to parse by position?

======================================================

You need not convert to a string; these functions will do:

     generate byte day = int(daymon/100)
     generate byte mon = mod(daymon,100)

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:  +45 8942 6090
Home:   +45 8693 7796
Email:  sj@soci.au.dk
__________________________________________ 


*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index