Announcement

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

  • How to store each estimate of multiple regressions in a loop command

    Hi,

    I am running regression commands similar to the followings:
    logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10
    est store E1

    foreach var of varlist x1-x1129 {
    logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10 `var'
    }
    In the loop command I would like to store each estimate of 1129 regressions for vars x1-x1129 as E2-E1130, but I am not sure how to insert "est store" within the command.
    Of note, var x1-x1129 have completely different names, such as aa_a_15_30018338, and I don't want to change var names if possible.

    Any suggestions or comments will be highly appreciated!

    Thanks,

  • #2
    You will increase your chances of useful answer by following the FAQ on asking questions.

    foreach var of varlist x1-x1129 {
    logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10 `var'
    est store e`var'
    }

    Although, I'm not sure how you work with 1100 stored estimates in any sensible way. You might look at Postfile. Alternatively, you can create a counter and a bunch of variables of all missing values before the loop and then write the parameters into specific observations creating a set of variables where each observation is an estimate, and each variable is a parameter estimate.

    Comment


    • #3
      Hi Phil,

      Thank you very much for your kind advice.
      I should have added the following information. I also have to read FAQ carefully again.

      I am using StataIC 14.

      What I want to do is to extract the p value of each regression by typing following commands after storing estimates.

      matrix p = J(1130, 1, .)
      forvalues i = 2/1130 {
      lrtest E1 E`i', force
      matrix p[`i', 1] = r(p)
      }
      matrix list p

      Then, I am going to do the same process by conditioning on the most significant `var' and repeat the process until none of the `var' reaches a preset significant level (4.43e-5=0.05/1129).
      Although I ran "est store e`var'", I was not sure how to type the subsequent command to generate the p-value list.
      That is why I wanted to store estimate as E2, E3, ..., E1130

      Although I tried the following, of course it did not work; it just generated 300 estimates of one regression.

      foreach var of varlist x1-x1129 {
      logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10 `var'
      forvalues i=2/1130{
      est store E`i'
      }
      }

      I also thought about using macros, such as local, but I could not get any answers by myself.

      Since I have not understood the last part of your comments yet, I have to figure out how it works and if it actually works on my data.
      But, meanwhile I will really appreciate any further advice or comments.


      Thanks,
      Last edited by Yuki Ishikawa; 11 Mar 2020, 19:57.

      Comment


      • #4
        Putting aside whether you should actually be doing this and whether your results will be anything but noisy...you could look at -stepwise- since it sounds like this is could be a stepwise process. Are your ~1100 variables representative of genes, out of curiosity?

        Comment


        • #5
          Hi Leonardo,

          Thank you very much for your suggestion.
          I think it is actually a kind of forward stepwise selection process. However, I cannot choose more than 10 variables and I also have to repeat this process ~1,100 times if I try to do this process.
          Furthermore, I have 10 different dependent variables to be analysed in the same way. That is why I am trying to figure out the way to make an efficient loop command.

          Yes, these ~1,100 variables are representative of genes. I am doing so-called "omnibus test" to find out the most significant variable, which affect a certain phenotype.

          Thanks a lot for your attention. If you have further suggestions or comments, please share in this forum.

          Comment


          • #6
            I am running regression commands similar to the followings:
            logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10
            est store E1

            foreach var of varlist x1-x1129 {
            logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10 `var'
            }
            I will say that your difficulty in getting helpful replies lies in lacking a reproducible example. This is covered in the FAQs, which you are prompted to read prior to posting. If I correctly understand your intent, you need a counter. Here is one way.

            Code:
            local i=2
            foreach var of varlist x1-x1129 {
            logit y cov1 cov2 cov3 cov4 cov5 cov6 cov7 cov8 cov9 cov10 `var'
            est sto E`i'
            local ++i 
            }
            Last edited by Andrew Musau; 13 Mar 2020, 02:15.

            Comment


            • #7
              Hi Andrew,

              First of all, I deeply appreciate your code posted here, which perfectly worked. As you pointed out, I completely missed a counter.

              Also, thank you very much for your advice about posting here. I should have put a reproducible example at the very beginning of this post.
              Below is the example similar to I wanted to do, but with far less number of variables.

              Code:
              sysuse auto, clear
              regress price weight length turn displacement gear_ratio
              est sto E1
              
              local i=2
              foreach var of varlist mpg-trunk {
              regress price weight length turn displacement gear_ratio `var'
              est sto E`i'
              local ++i 
              }
              
              matrix p = J(5, 1, .)
              forvalues i = 2/5 {
              lrtest E1 E`i', force
              matrix p[`i', 1] = r(p)
              }
              
              matrix list p
              
              p[5,1]
                         c1
              r1          .
              r2  .16482073
              r3  5.832e-23
              r4  .10730569
              r5  .85969059
              As it is clear here, I also completely forgot to mention that through this analysis I would like to evaluate the difference among nested models; those without `var' and those with each `var'.

              Again, I really appreciate visiting my post and spend time to understand what I wanted to do.
              I will definitely post in much better way next time.

              Comment

              Working...
              X