Announcement

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

  • Exporting p-values from ranksum into Excel

    Hi,

    I was able to create a loop to export p-values from chi2 and fisher's exact tests into excel using the code below. Is there a way this can be modified for continuous variables and ranksum tests?

    putexcel set "C:\Users\priscilla\stataexport", sheet("p-values") modify
    scalar k = 5
    foreach v of varlist categorical1 categorical2 categorical3 {
    tabulate exposurename `v' if cond1!=. & cond2!=., chi2 exact row col
    putexcel D`=k' = `r(p)'
    scalar k = k + 1
    }
    I tried using the code below, but it produces the following error message: "nothing found where expression expected"

    ranksum continuous1 if cond1!=.& cond2!=. & exposurename!=., by (exposurename)
    putexcel D6 = `r(p)'
    Is there any way I can fix this?

    Thanks!
    Priscilla

  • #2
    Originally posted by Priscilla Fung View Post
    [/INDENT]I tried using the code below, but it produces the following error message: "nothing found where expression expected"

    ranksum continuous1 if cond1!=.& cond2!=. & exposurename!=., by (exposurename)
    putexcel D6 = `r(p)'
    Is there any way I can fix this?
    You do not show your actual Stata output as recommended in FAQ Advice #12. If Stata cannot perform the test, e.g., if the -if- restrictions imply insufficient or no observations, then no p-value is calculated. The macro r(p) is empty, so Stata encounters

    putexcel D6 =
    resulting in the error. If you believe that there will be some instances that the test cannot be run and you are fine with that, you can use capture to bypass such instances. See

    Code:
    help capture


    Comment

    Working...
    X