*! version 1.1 November 1, 2006 @ 13:10:42 *! List information on (person specific) sequences * 1.0 SJ-version * 1.1 New format option allowed program define sqstattabsum version 9 syntax varlist(min=1 max=2) [if] [in] [, SUmmarize(varlist) gapinclude format(string) * ] // Sq-Data if "`_dta[SQis]'" == "" { di as error "data not declared as SQ-data; use -sqset-" exit 9 } preserve // 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 // Check if hand made varlist are constants above time if "`varlist'" != "" CheckConstant `varlist' local varlist `r(checked)' // Use egen-erated sequence-information if "`summarize'" == "" { 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 summarize "`SQlength' `SQelemcount' `SQepicount' `SQgapcount' `SQgaplength'" // Clean Summarize foreach var of local summarize { capture confirm variable `var' if _rc local summarize: subinstr local summarize `"`var'"' `""', all } capture format `summarize' `=cond("`format'"=="","%9.0g","`format'")' if _rc { di as error "format invalid" exit _rc } } // Output // ------ keep `_dta[SQiis]' `_dta[SQis]' `varlist' `var' `summarize' `iflist' `touse' quietly by `_dta[SQiis]': keep if _n==1 & `touse' foreach v of local summarize { tab `:word 1 of `varlist'' `:word 2 of `varlist'', summarize(`v') /// `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