Announcement

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

  • Converting p-values to z-values in a variable

    Hello, I am trying to find a way to transform a Stata variable of p-values to the corresponding z-value e.g. (0.025 --> 1.96). The only way I know how to do this conversion is through the display invnormal(p) command. However, I don't know how I can save this in a variable since display doesn't save the output anywhere (that I'm aware of). Any ideas?

    Thanks!

  • #2
    If p is a variable in your dataset containing p-values, then
    Code:
    generate z = invnormal(p)
    will create a variable containing z-values.

    Comment


    • #3
      I don't understand the organization of your workspace for this. Do you have a data set that includes a variable containing some p-values and you want to create a new variable with the z-values? If so
      Code:
      gen z_value = invnormal(p_value)
      does that.

      Do you have a p-value that is stored in a scalar or local macro and want a corresponding scalar or local macro containing the corresponding z-value?
      [/code]
      local z_value = invnormal(`p_value') // LOCAL MACRO CASE
      scalar z_value = invnormal(p_value) // SCALAR CASE
      [/code]

      Do you have a p-value that has just been produced by a command that leaves a p-value in r()?
      Code:
      local z_value = invnormal(`r(p)')
      will save it in a local macro for you.

      Basically, whatever the source of the p-value(s) is, and whatever kind of data structure you wish to store the result in, will be accomplished in ways like this, always relying on an expression using the -invnormal()- function, with an argument designated the source p-value and an appropriate assignment target on the left hand side, depending on how you want to save the result.

      Added: Crossed with #2.

      Comment


      • #4
        Oh wow, I didn't think it was that simple! Thanks!

        Comment


        • #5
          Oh wow, I didn't think it was that simple! Thanks!

          Comment

          Working...
          X