/*---------------------------------------------------------------------------- finddate -- Program to display the period for which data are available. finddate assumes that the data set is sorted in the order of the date variables. STATA programs called: _voptex Written by Sean Becketti, July 1989. ----------------------------------------------------------------------------*/ program define finddate version 2.1 quietly { if "%_*"=="" { di in bl "-> finddate varlist [if] [in], [date(datevars)] [nobs]" exit } mac def _varlist "opt ex" mac def _if "opt" mac def _in "opt" mac def _options "Date(str) Nobs" parse "%_*" if "%_if"~="" { mac def _if "%_if &" } if "%_if"=="" { mac def _if "if" } if "%_date"~="" { _voptex "%_date", vlist(vLiSt) parse "%vLiSt", parse(" ") mac def vLiSt if "%_4"~="" { di in re "No more than three date variables allowed" exit } mac def _year "%_1" mac def _ylbl "%_year" mac def _month "%_2" mac def _mlbl "%_month" mac def _day "%_3" mac def _dlbl "%_day" mac def _ndates = cond("%_2"=="",1,cond("%_3"=="",2,3)) conf ex %_year cap drop _y_lbl cap drop _m_lbl cap drop _d_lbl cap decode %_year, gen(_y_lbl) if ~_rc { mac def _ylbl "_y_lbl" } if (%_ndates>1) { conf ex %_month cap decode %_month, gen(_m_lbl) if ~_rc { mac def _mlbl "_m_lbl" } } if (%_ndates>2) { conf ex %_day cap decode %_day, gen(_d_lbl) if ~_rc { mac def _dlbl "_d_lbl" } } } gen int Obs = _n if "%_date"=="" { mac def _ndates = 1 mac def _year "Obs" mac def _ylbl "Obs" } if (%_ndates==1) { di in gr _c(11) "First" _c(22) "Last" di in gr _c(11) "%_year" _c(22) "%_year" di in gr "------------------------------" } if (%_ndates==2) { di in gr _c(16) "First" _c(41) "Last" di in gr _c(11) "%_year" _c(22) "%_month" /* */ _c(36) "%_year" _c(47) "%_month" di in gr "-------------------------------------------------------" } if (%_ndates==3) { di in gr _c(22) "First" _c(58) "Last" di in gr _c(11) "%_year" _c(22) "%_month" _c(33) "%_day" /* */ _c(47) "%_year" _c(58) "%_month" _c(69) "%_day" di in gr "-----------------------------------------------------------------------------" } mac def _S_FN "%S_FN" save t_e_m_p, replace parse "%_varlist", parse(" ") while "%_1"~="" { use t_e_m_p, clear keep %_if %_1~=. %_in if "%_nobs"~="" { mac def _N = Obs[_N] - Obs[1] + 1 mac def _n = _N count if Obs-Obs[_n-1]>1 in 2/l mac def _tag = _result(1) mac def _tag "(%_n/%_N/%_tag)" } if (%_ndates==1) { di in gr "%_1" in ye _c(11) %_ylbl`[1] /* */ _c(22) %_ylbl`[_N] " %_tag" } if (%_ndates==2) { di in gr "%_1" in ye _c(11) %_ylbl`[1] /* */ _c(22) %_mlbl`[1] _c(36) %_ylbl`[_N] /* */ _c(47) %_mlbl`[_N] " %_tag" } if (%_ndates==3) { di in gr "%_1" in ye _c(11) %_ylbl`[1] /* */ _c(22) %_mlbl`[1] _c(33) %_dlbl`[1] /* */ _c(47) %_ylbl`[_N] _c(58) %_mlbl`[_N] /* */ _c(69) %_dlbl`[_N] " %_tag" } mac shift } use t_e_m_p, clear erase t_e_m_p.dta mac def S_FN "%_S_FN" cap drop Obs cap drop _y_lbl cap drop _m_lbl cap drop _d_lbl } end capture program drop _voptex program define _voptex quietly { mac def _varlist "opt ex" mac def _options "Vlist(str)" parse "%_*" if "%_vlist"~="" { mac def %_vlist "%_varlist" } } end