Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: comparing dates: keep if dates<d(DDMMYYYY)


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: comparing dates: keep if dates<d(DDMMYYYY)
Date   Fri, 16 Jan 2009 17:12:58 +0100

Line for the server...

Re your extraction prob: I read in your dates, converted them via -g
date=date(sdate, "DMY")- and extracted components via

*****
g day =day(date)
g month =month(date)
g year =year(date)
*****

w/o problem. See -h dates_and_times, mark(extracting)-

HTH
Martin

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ana Gabriela
Guerrero Serdan
Sent: Friday, January 16, 2009 4:41 PM
To: [email protected]
Subject: st: comparing dates: keep if dates<d(DDMMYYYY)

Dear Stata users,

I am struggling to find a way how to keep observations within a date range
for different regions.

I have data like this:

list sdate  loc2prov

+---------------------------------+
sdate             loc2prov
---------------------------------
1.    1.8.2003         1             
2.    1.8.2003         1             
3.    1.8.2003          2           
4.    1.6.2003          2           
5.   20.8.2008           2           
---------------------------------
6.    1.9.2003          3           
7.    1.6.2003          4           
8.   1.11.2003          1           
9.    1.6.2003          6           
10.   1.11.2003         2             
---------------------------------
11.    1.5.2003          5           
12.    1.8.2003          6           
13.    1.8.2004           8           
14.    1.6.2004           18           
15.   1.11.2004           16

...............
...........etc



*I generate a date variable

gen Sdate=sdate

.
. gen date=date(Sdate,"DMY")

.
. format date %td

*then I compare and keep variables that belong to a specific region and
within a specific date.
*since I have many regions I first create a dummy indicating which variables
to keep:

gen k=1 if loc2prov==1 &  date<d(25aug2004)
(97890 missing values generated)

replace k=1 if loc2prov==2 &  date<d(25may2004)
(0 real changes made)

Why are missing values generated?

How can I tell stata to compare the date I have with another?

I also try creating separate variables for day, year and month  but its not
working 


thanks,

Gaby 





      
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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