Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Marking Levels of Categorical Variable


From   "Joseph Coveney" <[email protected]>
To   "Statalist" <[email protected]>
Subject   Re: st: Marking Levels of Categorical Variable
Date   Thu, 25 Sep 2008 11:23:10 +0900

jasonm wrote:

I have a categorical variable with 30 levels. How do I create a
variable that is equal to 1 if a category of the variable shows up
more than 10% of the time.

For example:
var  Percent
A      5
B      5
C      10
D      20
E      60
How would I create "newvar" equal to 1 for C, D, and E and equal to 0
for A and B?

--------------------------------------------------------------------------------

bysort var: generate byte more_than_ten = _N >= 10

If you mean strictly more than 10%, then change the >= to >.

Joseph Coveney


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index