Statalist


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

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


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: comparing dates: keep if dates<d(DDMMYYYY)
Date   Fri, 16 Jan 2009 11:09:11 -0500

You asked Stata to generate a variable if a condition was
true; whenever the condition is not true, the variable will
be missing:

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

What you want is probably

 gen k = (loc2prov==1)&date<td(25aug2004)

now k will =1 if the condition is true, and equal 0
if the condition is not true.

If you want more than one region included, or a range of
dates included, see -inlist()- and -inrange()-; eg,


 gen k = inlist(loc2prov,1,2)&inrange(date,td(25aug2003),td(25aug2004))

hope this helps,
Jeph

Ana Gabriela Guerrero Serdan wrote:

...

*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


*
*   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