Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Selective recoding of categorical variables

    Hi,

    I have a lot of categorical variables that are coded differently, some as 1 to 3, some as 1 to 5, and so on.

    There is no way to know from the names which ones are coded which way, so I am wondering if there is any method to detect the variables by the number of categories they have, and then recode them accordingly. e.g. I want variables with three categories to be labelled as "agree", "neutral, "disagree", and those with 5 as 'always', 'almost always', sometimes', 'often', 'never', and so on.

    Please let me know if there is any way to achieve this.

    Thank you.

  • #2
    distinct from the Stata Journal lets you identify variables with 3 or 5 distinct values. Missings are ignored by default.


    Code:
    . webuse nlswork
    (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
    
    . distinct, min(3) max(3)
    
    ---------------------------------
              |     total   distinct
    ----------+----------------------
         race |     28534          3
    ---------------------------------



    Comment


    • #3
      Thank you Nick! This is what I was looking for.

      Comment

      Working...
      X