Announcement

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

  • Creating and storing residuals in a loop

    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'==INDUSTRYGROUP , 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

  • #2
    Farah Ali Remember that you can edit posts within an hour of first posting. Please don't abandon threads like this.

    Everyone else: If interested please follow https://www.statalist.org/forums/for...uals-in-a-loop for a fuller question and at least one answer.

    Comment


    • #3
      My bad Nick......I didn't realize it was not the right way.....thanks for rectifying....

      Comment

      Working...
      X