Announcement

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

  • Looping Through Wide Data to Create Indicators

    Hi All,

    This question will probably seem simply inefficient, but it's necessary for an analysis I'm doing. I had to reshape data from long to wide based on an individual's ID code. But now I have over a thousand variables, when really I need only need ten indicator variables for an individual's status.

    My question is, is there a way to loop through these variables and create an indicator variable? The data looks like this:
    ID AppStatus1 AppStatus2 AppStatus3 AppStatus4
    ID 1 3
    ID 2 5
    ID 1 2
    And so forth, for over 1,000 of those application status variables. I want Stata to look through each AppStatus variable and pick up on any observations of "1" and generate a new indicator variable for any observations of "1" in any AppStatus variable (and so forth for values 2-10). Is there any way to do this?

    Thank you (from a beginner!)
    Last edited by Kelly McKnight; 03 Jun 2018, 22:15.

  • #2
    Code:
    help egen
    
    forval j = 1/10 {
        egen AnyMatch`j'  = anymatch(AppStatus*), values(`j')
    }

    Comment

    Working...
    X