Announcement

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

  • How to combine a range of similar variables (recordings)

    Dear Statalist community,

    I am currently struggling with how to combine a range of variables with similar information into one.

    To elaborate on this, I work with prescription information in a wide dataset; with each individual assigned a row, and each time (day, month, year) they filled/dispensed a prescription is recorded in separate columns, with the variable named disp_date1, disp_date2, disp_date3, etc. Everyone in the dataset has filled a prescription at least one time, with some more than a thousand times.

    What I would like to know is how many did fill a prescription more than let's say 400 times.

    Best,
    Haakon

  • #2
    perhaps,
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id disp_date1 disp_date2 disp_date3 disp_date4)
    1 100 75 250  .
    2  25 25   0 25
    3 250  0 250  0
    end
    
    egen x = rowtotal(disp_date*)
    egen wanted = total(x>400)
    Last edited by Øyvind Snilsberg; 12 May 2022, 02:40.

    Comment


    • #3
      Thanks for your reply, Øyvind!

      When I try to apply "egen x = rowtotal(disp_date*)", I get the sum of the time-values, and not how many times they filled their prescription.
      Not sure what "egen wanted = total(x>400)" creates.

      KR,
      Håkon

      Comment


      • #4
        I see. if there is one disp_date per prescription, replacing -rowtotal- with -rownonmiss- should sort you out. it not, a data example would be helpful.
        -total(x>400)- is the number of observations with x>400.

        Comment


        • #5
          Perfect, rownonmiss was exactly what I looked for! Thanks (tusen takk!;-))

          Comment


          • #6
            bare hyggelig!

            Comment

            Working...
            X