Announcement

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

  • Computing empirical p-value in bootstrap estimation

    I've written a program that computes some statistic and its covariance matrix via bootstrap. I wish to report the so-called "empirical p-value" (or "percentile bootstrap"?), which I understand corresponds to the probability of getting something more extreme than what was observed. In other words, count the number of values that are greater than or equal to the observed value, and divide by the number of values. In R (which we can think of as pseudocode) it would be something like:
    Code:
     pval = (1+sum(B >= coef))/(N+1)
    where B is the vector of bootstrap estimates and coef is the estimated coefficient.

    My questions are:
    1. Does this methodology make sense?
    2. How can I compute this conditional count in Stata (or Mata)? I couldn't find any function that lets me count the number of elements in a vector that satisfy certain condition.
    Thank you very much!

  • #2
    So assuming your vector B is instantiated as a variable in a Stata data set, and coef is a scalar constant:

    Code:
    gen Bgtc_count = sum(B >= coef)
    display "pval = " =(1+Bgtc_count[_N])/(_N+1)

    Comment


    • #3
      you can look at the code of asl_norm for an example. Type in Stata

      ssc install asl_norm
      viewsource asl_norm.ado
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        So assuming your vector B is instantiated as a variable in a Stata data set, and coef is a scalar constant:

        Code:
        gen Bgtc_count = sum(B >= coef)
        display "pval = " =(1+Bgtc_count[_N])/(_N+1)
        It's not. I know it's fairly easy to do this with variables, but I wanted to try a pure matrix approach because (i) I want to learn more and (ii) this is a program, so I'm trying to keep it "tidy" and not damage the user dataset.

        The issue for me is computing the count of elements in a vector that fulfill a criteria. I thought there was a "Matrix/Mata way of doing it", but if it isn't possible, I thought of the following method:
        Code:
        matrix A = (1\2\3\4)
        forvalues i = 1/`= rowsof(A)' {
            scalar coef = A[`i',1]
            if coef >= 3 local count = `count'+1
        }
        di "`count'"

        Comment

        Working...
        X