Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
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/