Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73249

Creating Data Series from Start and End dates

$
0
0
Hi,

I have following dataset, with variabes start_date and end_date. I am using Stata 12 version in a secured lab without internet.

Code:
* Example generated by -dataex-. To install:    ssc    install    dataex
clear
input float id str30(start_date end_date)
1 "1oct1981"  "1oct1986"  
1 "2oct1986"  "2oct1991"  
2 "15nov1991" "15nov1993"  
3 "20dec1995" "20dec2001"  
3 "21dec2001" "21dec2006"  
4 "15mar2005" "15mar2011"  
4 "16mar2011" "16mar2016"  
5 "7feb1995"  "7feb2000"  
5 "8feb2000"  "8feb2005"  
5 "9feb2005"  "9feb2010"  
6 "2jun2003"  "2jun2005"  
7 "16aug1995" "10march1997"
8 "2sep2001"  "10aug2005"  
9 "8jan2014"  "9jul2017"  
10 "14mar2005" "14mar2010"  
10 "15mar2010" "15mar2015"  
11 "1feb2013"  "15mar2014"  
12 "15may1997" "15may2002"  
13 "25nov2004" "19jan2007"  
14 "1jan2016"  "1jan2017"  
15 "21feb2012" "21feb2017"  
16 "17jul2001" "17jul2016"  
end
Code:
gen start_dt=date(start_date,"DMY")
format start_dt %td

gen end_dt=date(end_date,"DMY")
format end_dt %td
Now, I would like to create a variable "year_date" between the range of "15 June 2000" and "15 June 2016" so that I can keep the observations that are between the interval, in order to calculate population by year for 2000 - 2016."

Code:
keep if year_date>=start_dt & year_date<=end_d
I initially started with the code below but then realized that I would have to make two variables in that case.

Code:
gen year_date=mdy(6,15,start_dt)
I also tried the codes below but got errors.

Code:
local start = date("2000/06/15", "YMD")
local end = date("2010/06/15", "YMD")

egen year_date = seq(), from(`start') to(`end')
format %td date
I would appreciate your advice.

Thank you,
Pablo

Viewing all articles
Browse latest Browse all 73249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>