Announcement

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

  • Generating dichotomous variable based on precdedin P-Values

    Hi all,

    Hoping for a way to generate a 'flag' variable for low p-values from a proportional hazards test.

    The idea being that I run

    stcox var_1 var_2 var_3...var_k
    estat phtest, detail <- output contains p-value for each variable in the model

    ...and then...

    gen lowp=1 if (the corresponding variable p-value<0.05)

    I'm by no means a Stata expert so I'm not sure if it's viable to generate a variable based on part of a previous output, but if it is, would appreciate advice!

    Thanks,

    James

  • #2
    James,

    It doesn't seem to be possible (at least directly) following stcox, but I'm not sure it would make sense even if you could. If you have k variables in your model you will have at least k p-values (more if your variables are categorical). Meanwhile, your data set has n observations. How would you assign the p-values (or the 0/1 indicating it was <0.05) from some or all of those k variables to the n observations in your data set?

    Please provide more details about how you plan to use this information and perhaps we can come up with a solution or a good alternative.

    Regards,
    Joe

    Comment


    • #3
      I am not sure what you are trying to do, but I suspect this is not the best way to do it.

      I assume you really want to collect the names of the significant predictors;
      whether for later work, or just for display.If so, using test on every predictor is
      more appropriate than estat phtest, as it leaves the individual p-values behind.
      (strictly, returns them for further work or display)

      You can find out what is returned by any command using one or more of
      Code:
      return list
      ereturn list
      sreturn list

      The following (making extensive use of loops and local macros) should work
      (after adaption to your variable names):

      Code:
      unab preds : var1-var_k
      stcox `preds'
      foreach pred of local preds {
          test `pred'
          if r(p) < 0.05 {
                local sig `sig' `pred'
          }
      }
      di "`sig'"
      
      stcox `sig'
      Last edited by Paul T Seed; 19 Sep 2014, 12:22. Reason: I just corrected a couple of typos that would stop the code working

      Comment


      • #4
        Another way to get the p-values for the covariates is from the fourth row of the matrix r(table) that is output by stcox. Type matrix list r(table) to view it.

        Note also that estat phtest gives the p-values for the test of the proportional hazards assumption not the p-values for the significance of each covariate. Paul's method gives the latter, which is probably what you want. If you want the former that may take some doing.

        Comment


        • #5
          Thanks for your feedback gents! I am indeed looking for the p-values for the test of the proportional hazards assumption.

          To clarify, I've been tasked with presenting graphs detailing proportional hazards violations for several models of many variables. My thinking is that for the majority of variables, there won't be any violations, and thus producing a full spectrum of graphs (KM, log-log, survival-time etc.) isn't necessary.

          I was hoping to use the estat phtest as a gateway, and say "If the p-value of the assumption is less than [level], run the full spectrum of PH graphs, else don't run it"

          However I'm getting the sense that coding this might be a bridge too far, so perhaps I'm best off looking for another solution?



          Comment

          Working...
          X