Statalist


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

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


From   Ana Gabriela Guerrero Serdan <[email protected]>
To   [email protected]
Subject   Re: st: comparing dates: keep if dates<d(DDMMYYYY)
Date   Fri, 23 Jan 2009 16:42:48 -0800 (PST)

Thanks, 

Just had the time to work this out. I actually had to create some dummies first: 

tabulate   loc2prov, gen(Governorate)

gen k1= date<td(30may2004) & Governorate1==1
gen k2= date<td(20may2004) & Governorate2==1
gen k3= date<td(21may2004) & Governorate3==1
gen k4= date<td(15may2004) & Governorate4==1
gen k5= date<td(25aug2004) & Governorate5==1
gen k6= date<td(15may2004) & Governorate6==1
gen k7= date<td(30aug2004) & Governorate7==1
gen k8= date<td(29may2004) & Governorate8==1
gen k9= date<td(16may2004) & Governorate9==1
gen k10= date<td(20may2004) & Governorate10==1
gen k11= date<td(25may2004) & Governorate11==1
gen k12= date<td(17may2004) & Governorate12==1
gen k13= date<td(23may2004) & Governorate13==1
gen k14= date<td(19may2004) & Governorate14==1
gen k15= date<td(7jun2004) & Governorate15==1
gen k16= date<td(20may2004) & Governorate16==1
gen k17= date<td(19may2004) & Governorate17==1
gen k18= date<td(18may2004) & Governorate18==1


keep if k1==1 | k2==1 | k3==1 | k4==1 | k5==1 | k6==1 | k7==1 | k8==1 | k9==1 | k10==1 | k11==1 | k12==1 | k13==1 | k14==1 | k15==1 | k16==1 | k17==1 | k18==1 

I wonder if there is a way to tell stata to create one variable whenever the conditions above hold? 

I tried this but it doesnt work: 

gen dummy=1 if k*

invalid syntax
r(198);

 

regards, 
Gaby 


--- On Fri, 1/16/09, Jeph Herrin <[email protected]> wrote:

> From: Jeph Herrin <[email protected]>
> Subject: Re: st: comparing dates: keep if dates<d(DDMMYYYY)
> To: [email protected]
> Date: Friday, January 16, 2009, 10:09 AM
> 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/


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