Announcement

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

  • Increasing the number of variables to a explanatory covariates set

    I would like to estimate several linear regressions in which the explanatory set is increasing as follows.

    reg y x z1
    reg y x z1 z2
    reg y x z1 z2 z3
    ...
    reg y x z1 z2 z3.....z50

    what I am firstly interested in is in showing that R2 is increasing as the number of variables is higher. So after each regression, I want to save the R2 coefficient
    I tried to make a loop but it does not work:


  • #2
    Code:
    clear
    set obs 1000
    forv i = 1/50 {
        g z`i' = rnormal()
    }
    g y = rnormal()
    matrix R = J(50,2,.)
    matrix colnames R = r2 adj_r2
    forv i = 1/50 {
        qui reg y z1-z`i'
        matrix R[`i',1] = e(r2)
        matrix R[`i',2] = e(r2)
    }
    matrix list R

    Comment


    • #3
      Thank you George. Your code was very helpful (I only change e(r2_adj) at the second column-matrix)

      Comment


      • #4
        Yup. Sorry for the error.

        Comment

        Working...
        X