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

Re: st: Tabulate in reverse order of row and column values


From   Ichiro Fujikake <fujikake@cc.miyazaki-u.ac.jp>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Tabulate in reverse order of row and column values
Date   Fri, 25 Feb 2005 15:40:41 +0900

One way is to write a wrapper program for -tabulate-.

cap prog drop mytab
prog def mytab
    version 8
    syntax varlist(max=2) [if] [in] [, *]
    foreach X of var `varlist' {
        tempvar `X'r
        qui gen ``X'r'=-`X'
        local rlist "`rlist' ``X'r' "
        label var ``X'r' "`X'"
        qui levels `X', local(lev)
        local i=0
        foreach l of local lev {
            if `i++'==0 {
                label def `X' -`l' "`l'"
            }
            else {
                label def `X' -`l' "`l'" , add
            }
        }
        label val ``X'r' `X'
    }
    if "`options'"=="" {
        tab `rlist' `if' `in'
    }
    else {
        tab `rlist' `if' `in' , `options'
    }
end

sysuse auto, clear
tab foreign rep78
mytab foreign rep78

Ichiro

On 05.2.25 13:58, "Garry Anderson" <g.anderson@unimelb.edu.au> wrote:

> Hi,
> 
> Hi,
> 
> I wish to display a 2 x 2 table, but with the rows and columns displayed in
> reverse order of the values. There is a sort option, but sort displays the
> rows in descending order of frequency (and ascending order of the variable
> within equal values of frequency).
> 
> If I have two variables (row and column) with values of 0 or 1 and I do
> -tab row column-
> 
> I obtain
>        0    1
> 0   d     c
> 1   b     a
> 
> I would prefer
>       1     0
> 1   a     b
> 0   c     d
> 
> I could recode, but an option in tab would be the preferred solution to
> reverse the ordering on either or both of the rows and columns.  This
> reverse ordering is used by epitab commands such
> as csi.  It is usual to have exposed coded as 1, and diseased coded as 1.
> Any suggestions would be much appreciated
> 
> Cheers, Garry
> 
> *
> *   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/
> 


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index