Announcement

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

  • Creating dummy variable with one condition

    Hello everyone,

    I have a problem that I am hoping someone could help me with.

    I created a percentage variable (intensity_percentage) and on this basis I would like to create a dummy variable (intensity_dummy) with the values 0 or 1.

    This dummy variable should show the value "1" if the intensity_percentage variable shows at least twice a value greater than 100% within a firm-observation (gvkey, gvkey_year and year is given) and 0 otherwise.

    Does anyone have an idea about the respective command?

    Thank you very much in advance!

    Best regards,
    Anna


  • #2
    Sounds like

    Code:
    bysort gvkey gvkey_year year : egen intensity_dummy = total(intensity_percent > 100 & intensity_percent < . ; .)
    
    replace intensity_dummy = intensity_dummy  >= 2
    Please see https://www.statalist.org/forums/help#stata for how to give data examples (NB images of screenshots are not as helpful as you hope).

    Comment


    • #3
      Thank you very much Nick!

      Comment

      Working...
      X