*! version 1.0.0 August 1, 2006 @ 10:49:06 *! List information on (person specific) sequences program sqstattab2 version 9 syntax varlist(min=1 max=2) [if] [in] [, * ] // Sq-Data if "`_dta[SQis]'" == "" { di as error "data not declared as SQ-data; use -sqset-" exit 9 } // Catch varnames of if if "`if'" != "" { tokenize "`if'", parse(" =+-*/^~!|&<>(),.") while "`1'" != "" { capture confirm variable `1' if !_rc { local iflist "`iflist' `1'" } macro shift } } if "`iflist'" != "" CheckConstant `iflist', stop marksample touse, novarlist preserve // Check if hand made varlist are constants above time if "`varlist'" != "" CheckConstant `varlist' local varlist `r(checked)' // Use egen-erated sequence-information if `:word count `varlist'' == 1 { local SQlength: char _dta[SQlength] local SQelemcount: char _dta[SQelemcount] local SQepicount: char _dta[SQepicount] local SQgapcount: char _dta[SQgapcount] local SQgaplength: char _dta[SQgaplength] local autolist "`SQlength' `SQelemcount' `SQepicount' `SQgapcount' `SQgaplength'" // Clean Autolist foreach var of local autolist { capture confirm variable `var' if _rc local autolist: subinstr local autolist `"`var'"' `""', all } format `autolist' %4.0f } // Output // ------ keep `_dta[SQiis]' `_dta[SQis]' `varlist' `autolist' `touse' quietly by `_dta[SQiis]': keep if _n==1 & `touse' if `:word count `varlist'' == 1 { foreach var of local autolist { tabulate `var' `varlist', `options' } } else { tabulate `varlist', `options' } end program CheckConstant, rclass syntax varlist(default=none) [, stop] sort `_dta[SQiis]' foreach var of local varlist { capture by `_dta[SQiis]': assert `var' == `var'[_n-1] if _n != 1 if _rc & "`stop'" == "" { di as res "`var'" as text " is not constant over time; not used" local varlist: subinstr local varlist "`var'" "", word } if _rc & "`stop'" != "" { di as error "`var' is not constant over time" exit 9 } } return local checked "`varlist'" end