Announcement

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

  • Create a data subset if one variable takes one specific value at least once

    Dear community,

    I am trying to examine how war affects trade between enemy country pairs. Overall, I have a dataset with 17,407 country pairs. Out of these, some country pairs were engaged in war at one point in time. I am trying to keep those country pair ids, that had war=1 at least once. Can someone help me, please?

    So far, I can only keep id if war=1, but I do not wish to keep only wartime trade but all trade for country pairs that had been involved in war at least once.

    Thank you!

    Best,
    Ilona
    Last edited by Ilona Mazmanidou; 03 Feb 2023, 04:10.

  • #2
    This sounds like


    Code:
    egen anywar = max(war), by(id)
    
    keep if anywar == 1
    See https://www.stata.com/support/faqs/d...ble-recording/

    Comment


    • #3
      Thanks a lot! This was exactly what I was trying to do.

      Comment

      Working...
      X