Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: tabulate w/ fweights = 0


From   "Danielle H. Ferry" <[email protected]>
To   StataList <[email protected]>
Subject   Re: st: RE: tabulate w/ fweights = 0
Date   Mon, 26 May 2003 18:47:59 -0400

Nick, you are amazing. Thank you, thank you! This is really wonderful.

-Danielle

On 5/26/03 1:53 PM, "Nick Cox" <[email protected]> wrote:

> program tabzero
> *! NJC 1.0.0 26 May 2003
> version 8
> syntax varlist(max=2) [fweight/] [if] [in] [, matcell(str)]
> 
> quietly {
> marksample touse, strok zeroweight
> count if `touse'
> if r(N) == 0 error 2000
> 
> preserve
> tempvar freq
> if "`exp'" == "" local exp 1
> keep if `touse'
> bysort `varlist': gen `freq' = sum(`exp')
> by `varlist': keep if _n == _N
> 
> if `: word count `varlist'' == 2 {
> fillin `varlist'
> replace `freq' = 0 if _fillin
> drop _fillin
> }
> 
> local i = 1
> qui foreach v of var `varlist' {
> levels `v', local(v`i')
> local n`i' : word count `v`i++''
> }
> 
> if "`n2'" == "" {
> local n2 = 1
> local v2 "`2'"
> }
> 
> if "`matcell'" != "" {
> mat `matcell' = J(`n1',`n2',0)
> 
> tempvar i j
> egen `i' = seq(), block(`n2')
> egen `j' = seq(), to(`n2')
> 
> forval n = 1/`=_N' {
> matrix `matcell'[`=`i'[`n']',`=`j'[`n']'] = ///
> `freq'[`n']
> }
> 
> mat rownames `matcell' = `v1'
> mat colnames `matcell' = `v2'
> }
> }
> 
> label var `freq' "Freq."
> tabdisp `varlist', c(`freq')
> end



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index