Announcement

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

  • #16
    Hello there

    I'm hoping someone may be able to confirm/deny whether I've used the rcount() function correctly to derive a new count variable.

    I have a list of 17 variables used to define individual diseases that I would like to derive into a single count variable to determine the number of diseases present in each respondent. These variables take the form a_hcond1 - a_hcond17 (example using first 8 variables below). The variables are stored as bytes with label values -9 "missing", -7 "proxy respondent" -3 "refused" -1 "dont know" 0 "absent" 1 "present"

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(a_hcond1 a_hcond2 a_hcond3 a_hcond4 a_hcond5 a_hcond6 a_hcond7 a_hcond8)
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  1  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
    -7 -7 -7 -7 -7 -7 -7 -7
    -7 -7 -7 -7 -7 -7 -7 -7
    -7 -7 -7 -7 -7 -7 -7 -7
     1  1  0  0  0  0  0  0
    -7 -7 -7 -7 -7 -7 -7 -7
     0  1  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
    -7 -7 -7 -7 -7 -7 -7 -7
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  1  0  0  1  1  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  1  0  0  0  0  0  0
     0  1  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
    -7 -7 -7 -7 -7 -7 -7 -7
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  1  1  0  0
     1  0  0  1  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  1  0  0  0  0  0  0
    -7 -7 -7 -7 -7 -7 -7 -7
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  1  0  0  0  0  1  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  1  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     1  1  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  1  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     1  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  0  0  0  0  0  0  0
     0  1  1  1  1  1  0  0
    end
    label values a_hcond1 a_hcond1
    label def a_hcond1 -7 "proxy respondent", modify
    label def a_hcond1 0 "not mentioned", modify
    label def a_hcond1 1 "Mentioned", modify
    label values a_hcond2 a_hcond2
    label def a_hcond2 -7 "proxy respondent", modify
    label def a_hcond2 0 "not mentioned", modify
    label def a_hcond2 1 "Mentioned", modify
    label values a_hcond3 a_hcond3
    label def a_hcond3 -7 "proxy respondent", modify
    label def a_hcond3 0 "not mentioned", modify
    label def a_hcond3 1 "Mentioned", modify
    label values a_hcond4 a_hcond4
    label def a_hcond4 -7 "proxy respondent", modify
    label def a_hcond4 0 "not mentioned", modify
    label def a_hcond4 1 "Mentioned", modify
    label values a_hcond5 a_hcond5
    label def a_hcond5 -7 "proxy respondent", modify
    label def a_hcond5 0 "not mentioned", modify
    label def a_hcond5 1 "Mentioned", modify
    label values a_hcond6 a_hcond6
    label def a_hcond6 -7 "proxy respondent", modify
    label def a_hcond6 0 "not mentioned", modify
    label def a_hcond6 1 "Mentioned", modify
    label values a_hcond7 a_hcond7
    label def a_hcond7 -7 "proxy respondent", modify
    label def a_hcond7 0 "not mentioned", modify
    label def a_hcond7 1 "Mentioned", modify
    label values a_hcond8 a_hcond8
    label def a_hcond8 -7 "proxy respondent", modify
    label def a_hcond8 0 "not mentioned", modify
    I wish to know how many times each individual responded "present" to the 17 diseases, to give a count of their total number of diseases - in order to evaluate 'multimorbidity' based on number of disease present.

    I used the rcount() function as follows and received the corresponding output when tabulating the data:

    Code:
    egen LTC_count = rcount(a_hcond1 - a_hcond17), cond(@==1)
    
    . tab LTC_count
    
      LTC_count |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              0 |     28,751       56.38       56.38
              1 |     13,219       25.92       82.30
              2 |      5,120       10.04       92.34
              3 |      2,265        4.44       96.79
              4 |        919        1.80       98.59
              5 |        420        0.82       99.41
              6 |        164        0.32       99.73
              7 |         84        0.16       99.90
              8 |         28        0.05       99.95
              9 |         14        0.03       99.98
             10 |         10        0.02      100.00
    ------------+-----------------------------------
          Total |     50,994      100.00
    The output seems ok, but my very basic knowledge means I'm slightly unsure if I have applied this correctly. Does this output mean that e.g. 13,219 respondents answered "present" to only 1 disease, 5120 answered "present" to 2 diseases etc...


    Any help would be much appreciated.

    Lewis

    Comment


    • #17
      This is lengthy thread with intermittent postings over some years.

      I focus on #16 with some echoes of previous posts.

      The egen function rcount() is from egenmore (SSC) and FWIW is no longer recommended by its original author, myself. On the other hand at least one user is happy to continue using familiar code.

      Here is a case in point as since Stata 9 we have had anycount() in official Stata to do precisely what you want (and before it something else, neqany()): see help whatsnew8to9.

      I ran this code on your example.

      Code:
      . egen wanted = anycount(a_hcond*), values(1)
      
      .
      . egen LTC_count = rcount(a_hcond*), cond(@==1)
      
      .
      . assert wanted == LTC_count
      No news is good news: results are identical.

      Your interpretation is correct. Here is a spot check of your data example. We have one patient with 3 mentions and one with 5.

      Code:
      . tab wanted
      
        see notes |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |         74       74.00       74.00
                1 |         17       17.00       91.00
                2 |          7        7.00       98.00
                3 |          1        1.00       99.00
                5 |          1        1.00      100.00
      ------------+-----------------------------------
            Total |        100      100.00
      
      . list if inlist(wanted, 3, 5)
      
           +---------------------------------------------------------------------------------------------------+
       25. |      a_hcond1 |  a_hcond2 |      a_hcond3 |      a_hcond4 |  a_hcond5 |  a_hcond6 |      a_hcond7 |
           | not mentioned | Mentioned | not mentioned | not mentioned | Mentioned | Mentioned | not mentioned |
           |---------------------------------------------------------------------------------------------------|
           |                a_hcond8            |           wanted            |            LTC_co~t            |
           |           not mentioned            |                3            |                   3            |
           +---------------------------------------------------------------------------------------------------+
      
           +---------------------------------------------------------------------------------------------------+
      100. |      a_hcond1 |  a_hcond2 |      a_hcond3 |      a_hcond4 |  a_hcond5 |  a_hcond6 |      a_hcond7 |
           | not mentioned | Mentioned |     Mentioned |     Mentioned | Mentioned | Mentioned | not mentioned |
           |---------------------------------------------------------------------------------------------------|
           |                a_hcond8            |           wanted            |            LTC_co~t            |
           |           not mentioned            |                5            |                   5            |
           +---------------------------------------------------------------------------------------------------+
      
      .
      Last edited by Nick Cox; 17 Feb 2022, 11:12.

      Comment


      • #18
        Thanks for your speedy and insightful response, Nick. Much appreciated

        Comment

        Working...
        X