*! Version 1.0.0 (STB-58: sxd2) program define coding, eclass version 6.0 local varlist "required existing" local if "optional" local in "optional" parse "`*'" if "$S_E_cmd"=="coding" { error 301 } *******get the dependent variable************************** local c=1 local depvar " " local temp: word `c' of `varlist' local depvar `temp' *******get the first stage covariates************ local c=2 local first " " unabbrev `varlist' local n: word count `varlist' while `c'<=`n' { local temp: word `c' of `varlist' local first `first' `temp' local c=`c'+1 } *****determine the number of strata and second stage******* *****sample size for each stratum************************** tempvar grp_z grp_yz nobs qui egen `grp_z'=group(`first') qui egen `grp_yz'=group(`depvar' `first') qui egen `nobs' =count(`grp_z'), by(`grp_yz') preserve gen grp_z=`grp_z' gen grp_yz=`grp_yz' gen nobs=`nobs' di in white "============OUTPUT OF CODING FUNCTION============" collapse `varlist' grp_z (count) nobs, by (grp_yz) list, nodisplay nolabel noobs drop grp_z grp_yz nobs di in blue "for functions requiring first stage sample sizes/prevalences" di in blue "enter these in the order of grp_yz" di in white "============END OF CODING FUNCTION===============" restore,preserve est local cmd "coding" end