> -----Original Message-----
> From: Kim Price [mailto:[email protected]]
> Sent: Wednesday, October 23, 2002 1:43 PM
> To: [email protected]
> Subject: st: replacing incorrect dob values
>
>
> I need to replace some date of birth values that were entered
> incorrectly. The variable dob (V1) is entered as %d. I've
> been using
> variations on the following and coming up with error messages:
>
> replace V1=05sep2046 05sep1946 if id==434
>
> I want to change id 434's date from 05sep2046 to 05sep1946.
A couple things. First, read up on Stata's date formats (help date) --
Stata stores dates as integers that count the number of days after (or
before) 1 January 1960. So "05sep2046" is really stored as 31659. The
display format %d tells Stata to *display* the number 31659 as its
corresponding date.
You can get the number for a date with the mdy() function -- which takes
as arguments the numbers for month, day, and year you want. So
. di mdy(9,5,2046)
31659
You can also extract the month, day, and/or year of a date number with
the functions month(), day(), and year().
So, you probably want to do something like:
. replace V1 = mdy(9,5,1946) if id==434
Note that in the replace statement, you don't indicate the existing
contents, only what you want it replaced to.
If the problem is a y2k thing--and you want to simply take 100 years off
all the birthdates that are listed as occuring after 2002, you could do:
. replace V1 = mdy(month(V1),day(V1),year(V1)-100) if
year(V1)>2002
This says, "replace V1 with the date code corresponding to the month
already in V1, the day already in V1, and the year in V1 minus 100, only
for cases where the year in V1 is after 2002".
Hope this helps.
Nick Winter
>
> Any help will be greatly appreciated.
>
> *
> * 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/
>
*
* 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/