Announcement

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

  • Computing accuracy score on Stata

    Hello,

    I am trying to compare two Stata variables "yBestPred" and "compliance" and try to come up with the accuracy score.
    To compute the accuracy score, I need to divide the number of observations that shares the same value (either 0 or 1) for both yBestPred and compliance by the total number of observation.

    Let's say that my variables look something like below:

    Code:
    >> list yBestPred
    
    1.  1
    2.  1
    3.  1
    4.  0
    5.  1
    
    >> list compliance
    
    1.  1
    2.  0
    3.  1
    4.  1
    5.  1
    How can I do this in Stata? I know how to do this on Python, but just don't know how to do this on Stata.

    Thanks,

  • #2
    There are many ways to do this. One is

    Code:
    clear
    input yBestPred compliance
    1 1
    1 0
    1 1
    0 1
    1 1
    end
    
    // accuracy
    count if yBestPred==compliance
    display r(N)/c(N)
    Note that this approach is very basic, not very flexible, and not robust at all. For example, selecting a subset of observations would require more code; missing values are likely to mess up the result, etc.

    Best
    Daniel
    Last edited by daniel klein; 20 Oct 2019, 06:00.

    Comment


    • #3
      Discussion continued here.

      Comment

      Working...
      X