Statalist The Stata Listserver

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

st: RE: How to get 4-digit year number

From   "Nick Cox" <>
To   <>
Subject   st: RE: How to get 4-digit year number
Date   Thu, 16 Mar 2006 15:53:21 -0000

If I understand this correctly, you think it 
unreasonable that, for example, 

yofd(date("2006", "mdy")) 

returns missing. It seems reasonable to me. 
If you say your date variable is "mdy", 
Stata shrugs its shoulders at anything that
does not fit what you say. 

What you could do is something like this: 

gen byear2 = real(dateinc2) if byear == . 

and then check that byear2 contains what 
you want. 

If I'm misunderstanding, please show us 
some of the problematic data. 


Akihito Tokuhara
> I want to strip the dates to get only the 4-digit year 
> number, using the 
> code below:
> generate qyear=date(dateinc2,"mdy")
> format qyear %d        /* This formats the qyear into  12july1987  */
> generate byear=yofd(qyear)            /* This strips the 
> 4-digit year number 
> from the date */
> But if the dates only has 4-digit number, it does not work. 
> Those year 
> numbers become missing
> values in new variable.
> Is there any way to do all in few codes, including other 
> forms of dates 
> which are non-missing.

*   For searches and help try:

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