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: ordering of categories when cross-tabulating


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: ordering of categories when cross-tabulating
Date   Tue, 19 Oct 2010 13:13:16 +0100 (BST)

--- On Tue, 19/10/10, Vitorino, Maria Ana wrote:
> I'm trying to produce a simple cross-tabulation table with
> gender on the rows and how important people think a program
> X is on the columns.
> The categories for the columns are " Very important",
> "Somewhat important", "Not Important"
> 
> Is there a way I can guarantee that the order in which the
> column categories are displayed are (from left to right) "
> Very important", "Somewhat important", "Not Important".
> Stata usually orders them alphabetically but I'm interested
> in a specific ordering.

Sounds like you stored your variable as a string. This is 
almost always cumbersome. You are much better of transforming
that vrariable in a numeric variable, and attach the appropriate
value labels. That way you can also control the sort order in
the table.

*-------------------- begin example ------------------------
// create some example data
clear
set obs 100
gen u = runiform()
gen str20 x = cond(u<.25, "Very important", ///
              cond(u<.6, "Somewhat important", "Not Important"))

// transform x to numeric 
gen x2 = cond(x == "Very important", 1, ///
         cond(x == "Somewhat important", 2, 3)) if !missing(x)
// attach value labels
label define x2 1 "Very important" ///
                2 "Somewhat important" ///
                3 "Not important"
label value x2 x2

// tabulate
tab x2
tab x
*------------------------- end example --------------------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index