Leslie <[email protected]> asked,
> I am having a really hard time converting birthdates (19320904, long
> variable type) into an elpased date that STATA uses.
There are two approaches: (1) either you take the number 19320904 and
convert make three numbers from it, 1932, 9, and 04, and convert those,
or (2) you take the number 19320904, convert it to a string "19320904",
and convert that.
Here's solution 1:
. gen year = floor(value/10000)
. gen month = floor(value/100) - year*100
. gen day = value - year*10000 - month*100
. gen long date = mdy(month, day, year)
. format date %td
. drop month day year
Here's solution 2:
. gen str new = string(value, "%10.0g")
. gen long date = date(new, "YMD")
. format date %td
. drop new
Concerning this last, we had to specify optinal second argument "%10.0g"
with function string() so that 19320904 became "19320904" and not
"1.93e+07".
-- Bill
[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/