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: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
clear
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:
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/