I am trying to run the following code. The purpose is to capture industry and year wise residuals from the stated model.
It works fine. However, when I try to replace the i= "twodigcode"(i.e. two digit codes with one digit codes) i= "onedigcode, Stata still gives the same results. I have also changed the i =1/6. But the results donot change. Can someone please guide where I am going wrong or what am I missing. Thanks in anticipation.
Code:
forvalues y = 2015/2017 { // Define a for/next loop spanning years in sample forvalues i = 1/45 { // Define a for/next loop spanning the industries in the sample capture: reg INVESTMENT SALESGROWTH if y=='Years' & i=='twodigcode' , noconstant // estimate Jones-type regression silently, within ind-year samples capture: predict resid`++n' if e(sample), residuals // save residuals in temporary variable named 'residXXX', and increment the local counter capture: replace `rname'=resid`n' if e(sample) // update values of permanent variable with residuals estimated in line above capture: drop resid`n' //drop temporary variable } // NEXT INDUSTRY } // NEXT YEAR
0 Response to Creating and storing residuals in a loop
Post a Comment