Announcement

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

  • Save OR as new variables

    Dear Stata experts,

    I am calculating a model and would like to store the resulting OR and corresponding p-values as new variables.
    Unfortunately, I did not succeed with this so far. I tried reading in the forum and the stata help command.
    The outreg command also does help put I would prefer to have the variables.

    Thank you in advance for your help!

    Code:
    foreach x of numlist 1 2 3 4 5 6 7 8 9 10 11 12 13 14 {
    foreach y of varlist v1 v2 v3 v4 v5 v6 {
    display `x'
    display `y'
    *xtmelogit `y' c.total c.fear c.happy c.angry c.sad C01 if COU==`x', or || SCHOOL: 
    xtmelogit `y' c.total##(c.fear c.happy c.angry c.sad) i.C01 if COU==`x', or || SCHOOL:
    *outreg2 using motives`x'.xls, eform cti(odds ratio) dec(2) title(Table 1: motives all`x') excel 
    }
    }

  • #2
    Storing OR and p-values as variables might well not be useful to you, although storing them in local macros or scalars or in matrices might help you do something you want. I'd suggest that you describe the goal you want to accomplish and something of the context of your current research, and ask people to respond to that. My suspicion here is that you are trying to do something that won't be a good way to accomplish your ultimate goal.

    Comment


    • #3
      I agree with Mike Lacy. And note that the advice he gave you is also found in the FAQ (item 9):

      Asking about your real problem, not something else, may seem too obvious to mention, but do check http://xyproblem.info/.
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        something like this might work. it could be cleaned up (the empty first row could be fixed by an if statement on a counter).

        Code:
            sysuse auto, clear
            matrix B = J(1,3,.)
            matrix P = J(1,3,.)
            foreach x of numlist 0 1 {
                foreach y of varlist price mpg weight {
                    reg `y' displacement turn if foreign==`x'
                    matrix R = r(table)
                    matrix B = B \ R[1,1...]
                    matrix P = P \ R[4,1...]
                    
                }
            }

        Comment


        • #5
          Thank you for your answers!

          My suspicion here is that you are trying to do something that won't be a good way to accomplish your ultimate goal
          I think i have to agree here.

          First of all, I realised, that I have to delete the '##c.total interaction.

          What I would like to do, is to use the OR above for a regression with another continuous variable. 1-14 are countries.
          So, I wanted to see the relationship between v1-v6 and my variables c.fear c.happy c.angry c.sad.
          The resulting OR should be used as outcome variable in the regression with "prevalence of depression" as independent variable.

          In other words: I want to find out, whether the relationship between v1-v6, respectively on country level and c.fear c.happy c.angry c.sad, is influenced by the prevalence rate of depression in these countries.

          Unfortunately, i did not find a more elegant solution for this. Maybe I can do it within one model, like an interaction effect? W
          Happy to hear your ideas.

          Best,
          Johanna

          Comment


          • #6
            is prevalence rate a country-level variable?

            Comment


            • #7
              in reg form (you can you logit), maybe something like this?

              reg y fear happy angry sad c.prevalence#(c.fear c.happy c.angry c.sad)

              the interaction coefficients tell you how the fear/happy/etc coefficients vary with prevalence.

              but note that interactions can be hard to interpret in a non-linear model. I can't recall what the current status of Stata's margins command in this situation, but I do recall there are other canned programs that can do it. Give it some attention--may be a nothing burger.

              Comment


              • #8
                Thank you George. Yes, prevalence rate is a country level variable.
                If this is no problem because the other variables are not country level, I appreciate this solution.
                So I guess this is a cross level interaction?

                Margins might also be helpful, indeed.
                Thank you!

                I guess Mike Lacy or Bruce Weaver also agree that this is the better solution to accomplish my goal.

                Best,
                Johanna

                Comment

                Working...
                X