Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: find categorical variables


From   Jakob Petersen <jpeterb@essex.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: find categorical variables
Date   Thu, 22 Mar 2012 09:02:17 +0000

Statalist,
Looking for a way to distinguish categorical from other types of variables.
The following code is based on the assumption that the mean of a variable of all integers would be an integer, but _rc seems to take the value 7 here regardless - any ideas? Many thanks in advance.

** finding categorical variables ******
sysuse auto,clear
local catvarlist
foreach v of var * {
qui su `v',mean
cap confirm integer number `r(mean)'
if _rc==0 {
local catvarlist `catvarlist' `v'
}
}
di "`catvarlist'"
***************************************
*adapted from: http://www.stata-journal.com/article.html?article=dm0048


Jakob Petersen

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