Announcement

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

  • variable ssr0 not found after being generated in a foreach

    Hello dear stata community.
    Im using the replication data file of Moritz Schularick, When credit bites back (2013).
    The author use a local projection approach.
    The loop is working but the sum of ssr0 after the loop isn't. The error is... variable ssr0 not found. I don't understand why...
    there's the code and thanks for the help.

    foreach v of local justgdp {
    gen ssr0`v'=.
    gen ssr1`v'=.
    gen nobs`v'=.
    forvalues i =1/5 {
    forvalues j= 1/1 {

    qui reg `v'`i' pk_norm pk_fin srx_norm_prv srx_fin_prv `rhs7' dum1-dum13 ///
    if core==1 & (year<1928|year>1946), noconstant //alt
    qui reg `v'`i' pk_norm pk_fin `rhs7' dum1-dum13 ///
    if e(sample)==1, noconstant // null, same sample

    replace ssr0`v'=e(rss) if _n==`i'
    reg `v'`i' pk_norm pk_fin srx_norm_prv srx_fin_prv `rhs7' dum1-dum13 ///
    if core==1 & (year<1928|year>1946), noconstant
    eststo h`i'
    replace ssr1`v'=e(rss) if _n==`i'
    replace nobs`v'=e(N) if _n==`i'

    test pk_fin=pk_norm // amt test
    estadd scalar p_diff1 = r(p)
    test srx_norm_prv=srx_fin_prv // amt test
    estadd scalar p_diffsrx = r(p)
    sum pk_norm if e(sample)
    estadd scalar Norm = r(sum)
    sum pk_fin if e(sample)
    estadd scalar Fin = r(sum)

    }
    }
    }

    sum ssr0
    Last edited by Joffrey Bousquet; 08 Nov 2022, 12:42.

  • #2
    No, the code never creates a variable ssr0. It creates a series of several variables ssr0*, where * ranges over whatever values are stored in local macro justgdp. If you want summary statistics on all of them, then you can just change the final command to -sum ssr0*-. If you want to create a single ssr0 variable that in some sense incorporates all the ssr0* variables, go for it. But there is no variable named ssr0 created in that code.

    Added: In the future, when posting code, please surround it with code delimiters so that indentation and other aspects of formatting are preserved, making it more readable.

    Comment


    • #3
      Thank a lot for the help M. Schechter.

      Comment

      Working...
      X