Announcement

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

  • Automation of the calculation of Oster's bounds

    Hello,

    I need to calculate Oster's bounds for many regressions for various R^2 and various dependent variables (y1, ..., y10) and independent variables (x1,...x10). In each regression participates only one y and only one x. For example, he calculations for the 1st regression, of y1 on x1 without looping looks as follows:

    global controls a b c d f g h

    reg y1 x1 $controls , robust
    keep if e(sample)==1
    display e(r2)
    *.23529605

    display=e(r2)*1.1
    psacalc beta x1 , rmax(.25882565) delta(1)

    display=e(r2)*1.2
    psacalc beta x1, rmax(.28235526) delta(1)

    display=e(r2)*1.3
    psacalc beta x1, rmax(.30588486) delta(1)

    display=e(r2)*1.8
    psacalc beta x1, rmax(.42353289) delta(1)

    display=e(r2)*2.0
    psacalc beta x1, rmax(.4705921) delta(1)

    display=e(r2)*2.2
    psacalc beta x1, rmax(.51765131) delta(1)

    psacalc beta x1, rmax(1) delta(1)

    My question: how to calculate this in a loop of the type below or somehow to automate it in another way?

    foreach y in y1 y2 y3 {
    foreach x in x1 x2 x3 {
    ...
    }
    }


  • #2
    The following draft use -post- to save results left by eclass -regress- and rclass -psacalc-
    Code:
    sysuse auto , clear
    
    local yvars price
    local xvars foreign mpg
    local controls weight headroom trunk
    
    local levels 1.1 1.2 1.3 1.8 2.0 2.2 1
            
    local newvars delta beta str50 cmdline
    
    tempname fh 
    postfile `fh' `newvars' using "results.dta" , every(1) replace
    
    foreach y of local yvars {
        
        foreach x1 of local xvars {
    
            regress `y' `x1' `controls' , robust
    
            foreach level of local levels  {
    
                local rmax = min(1, cond(`level'==1, 1, e(r2)*`level') ) /* NB rmax <= 1 */
                
                psacalc beta `x1' , rmax(`rmax') delta(1)
                            
                post `fh' (r(delta)) (r(beta)) (e(cmdline))
            }
        }
    }
    
    postclose  `fh'

    Comment


    • #3
      Bjarte, thank you very much for your help!

      Comment


      • #4
        You might also be interested in some insights about Oster's bounds that I describe here:
        https://www.statalist.org/forums/for...00#post1598100
        Last edited by Sebastian Kripfganz; 12 Apr 2021, 04:55.
        https://www.kripfganz.de/stata/

        Comment


        • #5
          Many thanks, Sebastian, this is also a very useful post.

          Comment

          Working...
          X