Announcement

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

  • Collapse a dummy variable

    Dear All,
    I am trying to collapse my variable of interest by country and year. I have a dummy variable that takes a 1 if the variable of interest is grant and 0 if it's a credit. After collapsing data , the dummy variable gets values of 0.97 ... 0.5 .... . Is there a different way to keep values 0/1.

    This is the code:

    collapse (sum) Var of interest (mean) DummyVar, by(Year Country)

    Many thanks,
    Fairouz

  • #2
    The mean of a 0/1 variable will be zero if all observations in the group are 0 and one if all observations are 1. Otherwise, it will be a fraction between 0 and 1. If you want to impose a rule where the result is one if at least one observation equals one, and zero otherwise, you can use:

    Code:
    collapse (sum) Var of interest (max) DummyVar, by(Year Country)

    Comment


    • #3
      Perhaps like Andrew Musau I am not clear quite what you were expecting from a collapse of a {0, 1} variable. I will add that if you keep a count too, then the mean tells you how many 0s and 1s you have in the data. Further, keeping the minimum too tells you if there are any zeros.

      Comment

      Working...
      X