Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: using dates with inrange()

From   "Nick Cox" <>
To   <>
Subject   st: RE: using dates with inrange()
Date   Mon, 19 Apr 2010 15:56:10 +0100

You could use something like

... if inrange(date, mdy(8,15,1999), mdy(8,14,2000)) 


David Souther

I'm trying to figure out how to create a variable that coded according
to whether it falls in certain time periods in my dataset.  So, I've
got data like

input date

and I format the dates with

replace date = date(date, "MDY")
format date %td

but I want an indicator that is 1 if the dates are in the range Aug.
15, 1999 to Aug. 14, 2000 and indicator = 2 if in the range Aug. 15,
2000 to Aug. 14, 2001 and so on, but I cannot figure out how to get
inrange() to work (or some other method to create this indicator):

generate ind = .
replace ind = 1 if inrange(date, 15aug1999, 14aug2000)

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index