Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: RE: -statsby- with -tabulate-: confirming output


From   Kieran McCaul <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: -statsby- with -tabulate-: confirming output
Date   Wed, 29 Jan 2014 06:40:25 +0800

...


Hi Michael,

Sorry for my late reply.

The problem is that -statsby- is good at using results that are returned in macros (e() or r()), but what you want, proportions, are not returned after -tabulate- so there is no real advantage to using -statsby- in this case.

Try something like this which will give you everything you need in a dataset which you can save and then calculate whatever row or column percentages you need in that.:


clear *

sysuse auto.dta,clear
gen byte Select= price<6000
lab def lab_YesNo 0 "No" 1 "Yes", modify 
lab val Select lab_YesNo 

tab Select foreign, row col matcell(freq) matrow(select)
tab Select if foreign<., matcell(rowtotals)
tab foreign if Select<., matcell(t_coltotals)

matrix coltotals = t_coltotals' \ t_coltotals'   

matrix table = (select, freq, rowtotals, coltotals)
matrix colnames table = select domestic foreign select_total domestic_total foreign_total

preserve
clear 
svmat table, names(col)

list, abb(15)

*save filename

restore


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Michael McCulloch
Sent: Sunday, 26 January 2014 8:46 AM
To: [email protected]
Subject: Re: st: RE: -statsby- with -tabulate-: confirming output

Keiran,
I'm extending this example for another purpose, to build a table to calculate sensitivity and specificity.
Pretend that "Select" is a diagnostic test, and Domestic is the condition being tested for. 

sysuse auto.dta,clear
gen byte Select= price<6000
lab def lab_YesNo 0 "No" 1 "Yes", modify lab val Select lab_YesNo tab Select foreign, row statsby Domestic=(r(N)-r(sum)) Foreign=r(sum) total=r(N) nprop=r(mean) sd=r(sd), clear by(Select): summ foreign l, noobs

Is it possible to expand the resulting 2x2 table, so that I can display:
	sensitivity (car is domestic, or 38/52)
	specificity (car is foreign, or 9/22)
along with the exact confidence intervals?


Best wishes,
Michael McCulloch

--
Pine Street Foundation, since 1989
124 Pine Street | San Anselmo | California | 94960-2674
P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org

On Jan 25, 2014, at 12:41 PM, Kieran McCaul wrote:

> ...
> 
> 
> -tab- doesn't return row or column percentages.  The macros r(N), r(r), and r(c) simply contain the total N and the number of rows and columns.
> 
> If you create the variable "choose" as a byte rather than a string variable, the following will give you most of what you need.
> 
> 
> 
> sysuse auto.dta, clear
> 
> gen byte choose = price<6000
> 
> tab foreign choose, row
> statsby total=r(N) nchoose=r(sum) nprop=r(mean), clear by(foreign): 
> summ choose
> 
> 
> 
> 
> 
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Michael 
> McCulloch
> Sent: Sunday, 26 January 2014 2:51 AM
> To: [email protected]
> Subject: st: -statsby- with -tabulate-: confirming output
> 
> Hello,
> I'm seeking to create a table with -statsby-, combined with -tabulate-. 
> Might anybody have an idea why the row percentages calculated with -tab- by itself, are nor reproduced when -tab- is combined with -statsby-?
> Example code:
> 
> sysuse auto.dta,clear
> gen choose="yes" if price<6000
> replace choose="no" if price>=6000
> tab foreign choose, row
> statsby, clear by(foreign): tab foreign choose, row l
> 
> Best wishes,
> Michael McCulloch
> 
> --
> Pine Street Foundation, since 1989
> 124 Pine Street | San Anselmo | California | 94960-2674
> P: (415) 407-1357 | F: (206) 338-2391 | 
> http://www.PineStreetFoundation.org
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index