Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Splitting a numeric variable


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: RE: Splitting a numeric variable
Date   Thu, 15 Aug 2002 12:55:31 -0400

> -----Original Message-----
> From: VISINTAINER PAUL [mailto:[email protected]] 
> Sent: Thursday, August 15, 2002 12:13 PM
> To: '[email protected]'
> Subject: st: Splitting a numeric variable
> 
> Quick question.
> 
> I have a numeric variable (float) of the form:  19460515
> 
> The variable actually refers to the date, May 15, 1946.  
> Truncating and
> concatenating functions appear to operate only on string 
> variables.  What
> approach can I use to change this to the correct date?
> 
> Thanks.
> 
> Paul visintainer

Assuming the variable is called datevar:

  gen year = int(datevar/10000)
  gen month = int((datevar-year*10000)/100)
  gen day = datevar-year*10000-month*100
  gen newdate=mdy(month,day,year)
  format newdate %d

Nick Winter

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index