Announcement

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

  • the proportion of individuals (each individual has repeated ID)

    Dear all.

    Wish you all well.

    I am new to STATA and I would really appreciate If someone may help me to solve the problem.
    I am unable to find out the proportion of individuals (each individual has repeated ID) who has problem1 (yes=1). Thank you for help


    The data structure is as
    ID Problem 1 Problem 2
    1 0 1
    1 1 0
    1 0 1
    1 0 0
    2 1 0
    2 1 0
    2 0 0
    ……etc
    ...

    etc
    Last edited by Buyadaa Oyunchimeg; 11 Jan 2018, 17:53.

  • #2
    first, please read the FAQ which has excellent advice on asking questions and on how to show data so it is useful to others (e.g., what you show cannot be your actual data as spaces are not allowed in variable names in Stata); the following should help:
    Code:
    egen maxprob1=max(Problem_1), by(ID)
    sum maxprob1 if ID!=ID[_n-1]
    there are a number of other ways to get there also (e.g., read the help for -egen- and look at the "tag" function; note that since "Problem_1" is probably not the real variable name you will need to replace that with whatever your variable name actually is

    note that the above assumes that data is sorted by ID; if not, please do so before using the code shown

    Comment


    • #3
      Thank you Rich for reply. I thought maybe it is better to clarify the purpose of my study.


      I would like to find out:
      1. Separate proportion for each drug classes and each drugs over entire time nad by year
      2. Proportion of each drug classes and drugs by broader age group (<55, >55)
      I would really appreciate if anyone may find time to help to solve the problem.



      Thank you,

      Warm wishes,

      Data structure is as below:
      ID Antiplatelet drugs Lipid lowering agents Supply date
      Aspirin Clopidgrel Heparin
      0001 1 0 1 0 May 2002
      0001 0 0 0 1 March 2008
      0001 0 0 1 0 June 2016
      0001 0 0 0 0 Nov 2013
      0001 1 1 0 0 Sep 2003
      0002 0 1 0 0 July 2007
      0002 0 1 0 1 March 2006
      0002 0 0 0 1 Jan 2009
      0002 1 0 0 0 Feb 2010
      0002 1 1 0 0 June 2011

      Comment


      • #4
        Buyadaa:
        Rich gave excellent advice.
        A different approach could be:
        Code:
        . sort id
        
        . egen flag=rowtotal(Problem_1 Problem_2)
        
        . egen warning=tag(flag) if flag>=1
        
        . duplicates report id if warning==1
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment

        Working...
        X