Announcement

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

  • regression over different number of observations

    Hi everyone

    I would like to regress each variable separately on one independent variable. Furthermore, the first regression for each variable should be based on the observations 1 up to lets say 10, the second regression for each variable on the observations 11 up to 20 and so on. In a final step I would like to have all the coefficients listed in a table.

    This is the code I thought may work, but it gives the error massage " 'i' invalid obs no". Could anyone tell me where the mistake is?
    Any help would be very much appreciated!



    Code:
    clear all
    set more off
    
    sysuse auto
    
    postutil clear
    
    postfile bse str20 var float (beta1) using results, replace
    foreach s of varlist mpg-trunk{
     forvalues i= 1 (1)64{
      quiet reg price `s' in ā€˜i’ / ā€˜i’ +10
      }
      matrix r = r(table)
      post bse ("`s'") (r[1,2])
    }
    postclose bse
    use results, clear
    list
    Last edited by Philip Hiller; 03 Apr 2019, 07:22.

  • #2
    The syntax for -in- requires something that evaluates to a number on both sides of the "/". You need to force evaluation of `i' + 10. You can put `i' + 10 into a local and reference that, or evaluate `i' + 10 on the fly:
    Code:
    forvalues ... {
       local ip10 = `i' + 10
       quiet reg ... in `i'/`ip10'
    ....
    or
    Code:
    forvalues ... {
       quiet reg ... `i'/`=`i' + 10'
    ...

    Comment


    • #3
      Now it works. Thank you very much!

      Comment

      Working...
      X