Statalist The Stata Listserver


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

Re: st: converting dates formatted with dots


From   "Sebastian F. B�chte" <[email protected]>
To   [email protected]
Subject   Re: st: converting dates formatted with dots
Date   Mon, 29 Jan 2007 12:35:20 +0100

Ana,

you could use the -date- function which comes with Stata:

gen year=year(date(sdate,"dmy"))
gen month=month(date(sdate,"dmy"))
gen day=(date(sdate,"dmy"))

For more information on -data- check out the online help: -help date-

hth
Sebastian


On 1/29/07, Ana Gabriela Guerrero Serdan <[email protected]> wrote:
Hi,

I want to convert a variable that includes dates as
follows: day.month.year (e.g. 1.4.2005) into three
different variables for day, month and year (day=1,
month=4,year=2005)

I have tried the date commands but since I have dots
stata does not recognize them.

. list sdate incident sex agecat
+-------------------------------------------+
sdate   incident       sex    agecat
-------------------------------------------
1.   20.3.2003       x007   unknown   Unknown
2.   20.3.2003       x038      male   Unknown
3.   20.3.2003       x038      male   Unknown
4.   20.3.2003       x038      male     child
5.   20.3.2003       x038    female     child
-------------------------------------------
6.   20.3.2003       x038   unknown   Unknown
7.   20.3.2003       x038   unknown   Unknown
8.   20.3.2003       x038   unknown   Unknown
9.   20.3.2003       x038   unknown   Unknown
10.   20.3.2003       x038   unknown   Unknown
-------------------------------------------
11.   20.3.2003       x038   unknown   Unknown
12.   20.3.2003       x038   unknown   Unknown
13.   20.3.2003       x038   unknown   Unknown
14.   20.3.2003       x038   unknown   Unknown
15.   20.3.2003       x038   unknown   Unknown
-------------------------------------------
16.   20.3.2003       x038   unknown   Unknown
17.   20.3.2003       x038   unknown   Unknown
etc...


Break--
r(1);
. generate date=year(sdate)
type mismatch
r(109);


Any ideas?

thanks,
Gaby
*
*   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/



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