Announcement

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

  • Question about odds ratio per continuous variable

    Hello,

    I am looking for a STATA syntax in which the corresponding odds ratio and 95% confidence interval is calculated for each value of a continuous variable and then plotted graphically over the value of the continuous variable. The continuous variable contains a total of 1,264 values.

    I would be very grateful for your help.

    Best regards,
    David

  • #2
    An odds ratio is a comparison, so an odds ratio for all values is logically impossible. You need to choose one vale as the reference, and leave that out. Alternatively, you could look at the odds, not the odds ratio, and have a number for all values. Which one do you want?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      David:
      welcome to this forum.
      I'm probably missing out on something, but why considering odds or odds ratio for a continuous variable?
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Is there an interaction term? Otherwise the OR (for another unit increase in x) should be the same regardless where x is.

        Comment


        • #5
          Thank you all very much for your quick replies.

          To solve the problem, I will give you the background information:
          A dependent dichotomous variable Y (cases and controls) and an independent continuous variable X (radiation dose) are used to calculate the odds ratio using logistic regression. My goal is to calculate odds ratios for each value of the continuous variable.

          A similar question to my problem was already asked in this forum under the following link:
          https://www.statalist.org/forums/for...le-of-interest

          The main difference here is that my independent continuous variable contains 1,264 values (not just 4). Is there a STATA syntax to do this?

          Best regards
          David

          Comment


          • #6
            David:
            I usually feel terriƬble when it comes to categorize a continuous predictor, but 1264 different values are kinda overkill.
            Is there something in the literature of your reserach field that can support the categorization of X in, say, four levels?
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              From looking at the other posting David cited in #5, I'm thinking he wants predicted *odds* with CIs on those predictions. As Carlo points out, such a graph might be nicer for a smaller number of points in the range of the predictor, but setting aside that concern, here's a way to get the predicted ln(odds) and CI for each observed value of X, and exponentiate to get the corresponding odds. Perhaps there's some nicer way to do this with -margins- or -predictnl-, but the DIY approach was easiest for me.
              Code:
              // Create illustrative data.
              clear
              set seed 1234
              set obs 2000
              gen x = round(runiform() * 2000)
              gen ystar = 1 + 2 * x + rlogistic(0,500)
              gen y = ystar > 2000
              tab y
              egen just1 = tag(x) // about 1300 different values of x
              //
              // Run the model and obtain predicted ln(odds) and se(ln(odds)) for each observed value of x
              logistic y x
              predict lnodds if just1,  xb
              predict selnodds if just1, stdp
              //
              // Odds and CI
              gen odds = exp(lnodds)
              gen lower = exp(lnodds - 1.96*selnodds)
              gen upper = exp(lnodds + 1.96*selnodds)
              // graph
              twoway (scatter odds x, mcolor(blue) msize(tiny)) ///
                     (rspike lower upper x, lcolor(red)) if just1, ///
                     title(Predicted Odds with CI)
              graph rename whole      
              //
              // You could zoom in on part of the x range to see what underlies the preceding
              twoway (scatter odds x, mcolor(blue) msize(tiny)) ///
                     (rspike lower upper x, lcolor(red)) if just1 & inrange(x, 100, 200), ///
                     title(Predicted Odds with CI)
              graph rename part








              Comment

              Working...
              X