Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: combining frequency tables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: combining frequency tables
Date   Mon, 23 Feb 2009 18:18:50 -0000

I don't have your data and more importantly can't reproduce your error.
Joining matrices rowwise works for me. There is no programming required,
just matrix manipulations as documented under -matrix-. 

. mmdesc rep78 mpg price if foreign

             Missing          Total  Missing/Total
rep78              1             22      .04545455
  mpg              0             22              0
price              0             22              0

. mat A = r(table)

. mmdesc rep78 mpg price if !foreign

             Missing          Total  Missing/Total
rep78              4             52      .07692308
  mpg              0             52              0
price              0             52              0

. mat B = r(table)

. mat C = A, B

. mat li C

C[3,6]
             Missing          Total  Missing/Total        Missing
rep78              1             22      .04545455              4
  mpg              0             22              0              0
price              0             22              0              0

               Total  Missing/Total
rep78             52      .07692308
  mpg             52              0
price             52              0

Nick 
[email protected] 

Shehzad Ali

I tried implementing your suggestion but the output isn't what I was 
wanted. -mdes- (original) gives me missing, total and missing/total for 
each time point and each treatment separately and I want them all on one

table. I tried -mmdes- as suggested for each use variable separately and

saved each result like this:

-mmdes- for use1

mat A

-mmdes- for use2

mat B

and so on.. and finally:

mat F = A, B, C, D, E

or 

mat F = A + B + C + D + E

mat list F

This returns only one row for use1 with zero missing and nothing for any

other use variables or time points. Am I doing something wrong here (pls

excuse my poor knowledge of stata programming)?

On Feb 23 2009, Nick Cox wrote:

>-findit mdesc- reveals that it is
>a program by Rose Anne Medeiros, who once wrote a program called -njc-,
>for which I am not responsible. Here is a matrix version of her
program,
>for which she is not responsible. 
>
>*! mmdesc 1.0 NJC 23 February 2009 
>* mdesc 1.0 RAM 18 JULY 2008
>* Returns a table with number missing, total, and missing/total
>program mmdesc, rclass byable(recall)
>version 8 
>syntax [varlist] [if] [in]
>tempvar touse
>mark `touse' `if' `in'
>local nvars : word count `varlist' 
>tempname matrix 
>matrix `matrix' = J(`nvars', 3, .) 
>local i = 1 
>quietly foreach var of local varlist {
>	count if missing(`var') & `touse' 
>	matrix `matrix'[`i', 1] = r(N) 
>	count if `touse'
>	matrix `matrix'[`i', 2] = r(N) 
>	matrix `matrix'[`i', 3] = `matrix'[`i',1] / `matrix'[`i',2] 
>	local ++i  
>}
>matrix rownames `matrix' = `varlist'                     
>matrix colnames `matrix' = Missing Total Missing/Total 
>matrix list `matrix', noheader 
>return matrix table = `matrix' 
>end
>
>Once you run this, you can save its results by e.g. 
>
>mat A = r(table) 
>
>... 
>
>mat B = r(table) 
>
>...
>
>mat C = A + B 

Shehzad Ali

>Another (perhaps) simple question: is it possible to add different 
>frequency tables together to form a combined single table in Excel?
>
>I have two group variables (say, var1: type of treatment; and var2:
time
>
>point of observation) and 5 use variables. So an observation would be
>for 
>treatment A at time point 1. I want to know the number of missing
values
>
>for each use variable for each treatment group and each time point.
Also
>
>for each use variable there are 'if' conditions, so I can't do the 
>frequency count in one go. Here is what I am doing using a user written

>programme -mdesc- or -missing-:
>
>by treatment timpoint: mdesc use1 if (condition1 condition2)
>
>by treatment timpoint: mdesc use2 if (condition3 condition4)
>
>and so on. 
>
> 
>Now I want to combine all these counts for all timepoints and treatment

>groups to get a single table that I can export to Excel. Is there any
>way I 
>could do that?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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