Announcement

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

  • Grouped data to individal patient data

    I have some binary grouped data like events1, events2, n1, n2 (see below). But I want to translate it to individual patient data, is there any method? Thanks.

    n1 events1 n2 events2
    246 13 312 25


  • #2
    Code:
    gen long obs_no = _n
    reshape long n events, i(obs_no) j(event_type)
    expand n
    by obs_no event_type, sort: gen byte occurred = (_n <= events)
    drop n events obs_no
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thanks Schechter. This code helps a lot. And will use the command for my futher data examples.
      Best regards
      Chang

      Comment

      Working...
      X