Bookmark and Share

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

[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:19:47 +0100 (BST)

--- On Tue, 19/10/10, Phil Clayton  wrote:
> I would suggest encoding the string variable as a numeric
> variable with value labels. That way you can order them
> however you like, and it's more compatible with various
> commands. See -help encode- and also [U] 23.2 Categorical
> string variables.

Using -encode- is a good suggestion. Here is an example:

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

// create label
label define x2 1 "Very important" ///
                2 "Somewhat important" ///
                3 "Not important"
// use encode to transform x to numeric variable x2
encode x, label(x2) gen(x2)

// tabulate
tab x2
tab x
*----------------------- end example -------------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

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


*   For searches and help try:

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