Announcement

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

  • how to write a loop to regress the same model with different levels of a variable

    Hello everyone,

    Currently I have this set of codes, I'm running the same regression for different levels of xxx (now I divide it into 4 levels). I don't know how to write them using a loop, because if I want to divide xxx into say 10 levels, it would be cumbersome to repeat listing out the regression 10 times. So I would like a loop to make it easier. How can I achieve this?

    Code:
    egen quantiles_xxx = xtile(xxx), by(year industry) nq(4)
    
    probit y x1 x2 x3 x4 i.industry i.year if quantiles_xxx == 1 ,vce(cluster symbol)
    est store model_1
    
    probit y x1 x2 x3 x4 i.industry i.year if quantiles_xxx == 2 ,vce(cluster symbol)
    est store model_2
    
    probit y x1 x2 x3 x4 i.industry i.year if quantiles_xxx == 3 ,vce(cluster symbol)
    est store model_3
    
    probit y x1 x2 x3 x4 i.industry i.year if quantiles_xxx == 4 ,vce(cluster symbol)
    est store model_4
    
    logout, save(abcd) word replace fix(5): ///
    esttab model_1 model_2 model_3 model_4, ///
    b(%6.3f) z(%6.3f) ///
    star(* 0.1 ** 0.05 *** 0.01) ///
    scalar(N r2_p) compress nogap
    Thanks a lot for any suggestions

  • #2
    Code:
    egen quantiles_xxx = xtile(xxx), by(year industry) nq(4)
    
    levelsof quantiles_xxx, local(quantiles)
    foreach q of local quantiles {
        probit y x1 x2 x3 x4 i.industry i.year if quantiles_xxx == `q' ,vce(cluster symbol)
        est store model_`q'    
    }

    Comment


    • #3
      Wow thanks a lot Clyde! This is exactly what I need!

      Comment


      • #4
        One more question, sorry if this is not so relevant to this topic. After getting the regression results for dividing the same into 10 levels, I used the same esttab (from SSC) to create a table and export it in word format, but there are too many columns that couldn't fit in the page and the columns overlap one with another. Is there any other way to get a neater table? Thanks!

        Comment


        • #5
          This is off topic and you should start a new thread for this. These threads are not dialogs between a questioner and a responder. They are read by others who come here and selectively read topics they are interested in, and by yet others come and specifically search topics they are interested in. When a thread goes off topic it wastes all these other people's time. So please post this in a new thread.

          That said, I don't use -esttab- very often myself and have only a rudimentary understanding of it. I wouldn't be able to answer this question anyway. In a new thread with a title that suggests the topic, somebody who knows will see it and answer it. Here in an off-topic thread it might well languish unanswered indefinitely.

          Comment


          • #6
            Sorry about that and thanks again for helping me with the loop!

            Comment

            Working...
            X