#delimit ; clear; set more off; set memory 200000; set maxvar 32000; version 9.0; capture: log close; log using "c:\data\psid\eco 721\lab6.log", text replace; /*********************************************************************************/ /* Program: lab6_disc_haz.do -- Stata do file to read 1968-87 longitudinal data */ /* from the PSID, construct spell information for the first observed */ /* non-left-censored marriage spell for each household, construct */ /* spell records and variables, and estimate discrete-time hazard models*/ /* */ /* Authors: D. Ribar April 2009 */ /*********************************************************************************/ /* Read/input data set */ use "c:\data\psid\eco 721\psid_cons_68_87.dta", clear; /* Sort data by household identifier (int_id) and the observation year */ sort int_id year; /*********************************************************************************/ /* Clean and construct marriage spell records */ /*********************************************************************************/ /* Drop records starting with any breaks in the longitudinal sequence */ by int_id: gen compyear = year[1] + _n - 1; by int_id: gen yearflag = year - compyear; by int_id: replace yearflag = year - compyear - 1 if year>=1974 & year[1]<1974; drop if yearflag>0; drop compyear yearflag; /* Find year of first observed transition from being unmarried to married */ gen umtranyr = .; by int_id: replace umtranyr = year if tvcurmar[_n]==1 & tvcurmar[_n-1]==0 & _n>1; by int_id: replace umtranyr = umtranyr[_n-1] if umtranyr[_n-1]<. & _n>1; by int_id: replace umtranyr = umtranyr[_N]; label var umtranyr "Year of start of marriage spell"; /* Drop observations prior to first non-censored marriage spell and observations */ /* without transitions into marriage */ drop if year < umtranyr; /* Artificially right censor sequences that extend over the 1973 gap */ drop if year>=1974 & umtranyr<=1974; /* Find year of first observed transition from being married to unmarried */ gen mutranyr = .; by int_id: replace mutranyr = year-1 if tvcurmar[_n]==0 & tvcurmar[_n-1]==1 & _n>1; by int_id: replace mutranyr = mutranyr[_n-1] if mutranyr[_n-1]<. & _n>1; by int_id: replace mutranyr = mutranyr[_N]; label var mutranyr "Year of end of marriage spell"; /* Drop observations after transition out of marriage */ drop if year > mutranyr; /* Create spell variables (duration and exit indicator) */ by int_id: gen marctdur = _n; by int_id: gen mardexit = mutranyr<. & _n==_N; label var mardexit "Did marriage end in next year?"; label var marctdur "Elapsed cumulative duration of marriage"; /* Create dummy variables corresponding to each possible spell duration */ tabulate marctdur, ge(d) nofreq; /* Create employment indicator */ gen employed = tvhdemps==1; /****************************************************************************/ /*** Estimate models ***/ /****************************************************************************/ /* Tabulate Kaplan-Meier hazards (exits vs. risk set at each duration) */ table marctdur, contents (n mardexit sum mardexit mean mardexit); /* Run discrete time hazard model with no controls for duration dependence */ logit mardexit tvage year employed tvwhite tvblack tvhdeduc; /* Run discrete time hazard model with linear control for duration dep. */ logit mardexit marctdur tvage year employed tvwhite tvblack tvhdeduc; /* Run discrete time hazard model with dummy controls for duration dep. */ logit mardexit d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 tvage year employed tvwhite tvblack tvhdeduc if marctdur < 12; log close; clear; #delimit cr