Announcement

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

  • How to collapse multiple observations into 1?

    I am analyzing studies on the cost-effectiveness of vaccines in different countries. Each study has multiple observations for each population/strategy it is evaluating. Part of the analysis is at the study level, so I want a single observation for each study that contains all the different countries evaluated in that study. Is this possible with the way my data is set up?

    What I have:
    Study # Ratio # Country1 Country2 Country3
    1 1 US Canada
    1 2 Mexico Canada
    1 3 US
    1 4 Mexico


    What I want:
    Study # Ratio # Country1 Country2 Country3
    1 1 US Canada Mexico

    Thanks!

  • #2
    I hope this will point you in the right direction:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(Study Ratio) str6(Country1 Country2) str1 Country3
    1 1 "US"     "Canada" "."
    1 2 "Mexico" "Canada" "."
    1 3 "US"     "."      "."
    1 4 "Mexico" "."      "."
    end
    
    reshape long Country, i(Study Ratio) j(countrynr)
    drop if Country=="."
    contract Study Country
    drop _freq
    bysort Study: gen j = _n
    reshape wide Country, i(Study) j(j)
    list, noobs
    
      +----------------------------------------+
      | Study   Country1   Country2   Country3 |
      |----------------------------------------|
      |     1     Canada     Mexico         US |
      +----------------------------------------+

    Comment

    Working...
    X