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   Michael McCulloch <[email protected]>
To   [email protected]
Subject   Re: st: RE: -statsby- with -tabulate-: confirming output
Date   Sat, 25 Jan 2014 16:45:37 -0800

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/


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