Announcement

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

  • average of one variable, uniqueness of another variable

    I am pretty inexperienced with Stata -- hoping someone can help me here, as I can't figure out how to word what I am trying to do in order to google:

    I have a list of patients for whom each has an estimated value provided by a physician.

    In this Example 1 below, there are 5 patients, with an average estimate of 68.75 (one missing value) made by 3 unique physicians.

    Example 1
    estimate physician
    patient #1 50 1
    patient #2 50 2
    patient #3 100 3
    patient #4 missing 3
    patient #5 75 3
    68.7
    In Example 2 below, there are 9 patients, with an average estimate of 67.8 (two missing values) made by 5 unique physicians.

    Example 2
    estimate physician
    patient #1 50 1
    patient #2 50 2
    patient #3 100 3
    patient #4 missing 3
    patient #5 75 3
    patient #6 75 4
    patient #7 missing 5
    patient #8 50 6
    patient #9 75 6
    67.8

    How can I write code to determine the number of unique physicians that contributed to the average estimate value?

    Thank you in advance!

    Judith

  • #2
    your example data is not nearly as helpful as it. could be - please read the FAQ (or, at least, the part dealing with -dataex-); I think that the following user-written command will help: -distinct-; use -search- to find and download

    Comment


    • #3
      Here is one approach, guessing the structure of your data.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(group physician observation)
      1 1 1
      1 1 .
      1 2 2
      1 3 3
      1 4 .
      1 5 .
      2 1 1
      2 1 2
      2 2 3
      2 2 .
      end
      
      frame put group physician if !missing(observation), into(count)
      frame count{
          contract group physician
          collapse (count) physician, by(group)
      }
      frlink m:1 group, frame(count)
      frget wanted= physician, from(count)
      drop count
      frame drop count
      Res.:

      Code:
      . l, sepby(group)
      
           +--------------------------------------+
           | group   physic~n   observ~n   wanted |
           |--------------------------------------|
        1. |     1          1          1        3 |
        2. |     1          1          .        3 |
        3. |     1          2          2        3 |
        4. |     1          3          3        3 |
        5. |     1          4          .        3 |
        6. |     1          5          .        3 |
           |--------------------------------------|
        7. |     2          1          1        2 |
        8. |     2          1          2        2 |
        9. |     2          2          3        2 |
       10. |     2          2          .        2 |
           +--------------------------------------+

      Comment


      • #4
        I rewrote example 2 using dataex:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(patient estimate physician)
        1  50 1
        2  50 2
        3 100 3
        4   . 3
        5  75 3
        6  75 4
        7   . 5
        8  50 6
        9  75 6
        end
        I am trying to write code that determines the number of unique physicians that contributed non-missing values to "estimate." In this example, the answer is five unique physicians: physicians 1, 2, 3, 4, and 6. Physician 5 is not counted because there is a missing value for estimate for patient 7, the only patient for whom she was the physician.

        Comment


        • #5
          Thank you Andrew Musau for your quick reply even before I posted appropriately with dataex. I don't think the way you posted applies to my example because I don't have "groups" of patients in my data. Rich Goldstein thank you also for your quick response, I hope my question is now clearer with the example.

          Comment


          • #6
            if you have installed -distinct-, here is one way (but I'm still not sure I understand what you want or why):
            Code:
            . distinct physician if estimate<.
            
            ----------------------------------
                       |     total   distinct
            -----------+----------------------
             physician |         7          5
            ----------------------------------

            Comment


            • #7
              Thank you!! that worked.

              Comment

              Working...
              X