Announcement

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

  • Invalid name error in Stata simulation syntax

    Hi everyone

    I'm doing a simulation study following Adkins & Gade (p.26-27) and can't figure out an embarrasingly simple question on Stata syntax. When I run the code below, Stata returns
    Code:
    ‘sim’ invalid name
    The syntax is pasted from the document and should be fine. I've tried
    Code:
    `sim´
    to no avail, and I wonder if anyone here might know where the problem lies.

    Here is the simulation:
    Code:
    global nobs = 200
    global nmc = 1000
    set seed 10101
    set obs $nobs
    
    scalar slope = 1 /* regression slope */
    scalar sigma = 10 /* measurement error in y */
    scalar sige = .1 /* amount of measurement error in e */
    scalar gam = 1 /* instrument strength */
    scalar rho = .5 /* correlation between errors */
    scalar alpha=.05 /* test size */
    
    gen z = 5*runiform()
    gen y = .
    gen x = .
    gen u = .
    
    program regIV, rclass
    tempname sim
        postfile ‘sim’ b biv se se_iv p_ls p_iv using results, replace
        quietly {
    
        forvalues i = 1/$nmc {
            replace u = rnormal()
            replace x = gam*z+rho*u+rnormal(0,sige)
            replace y = slope*x + u
            reg y x
                scalar b = _b[x]
                scalar se = _se[x]
                scalar lb = b - se*invttail(e(df_r),alpha/2)
                scalar ub = b + se*invttail(e(df_r),alpha/2)
                scalar pv = slope<ub & slope>lb
    
            ivreg y (x=z)
                scalar biv = _b[x]
                scalar seiv = _se[x]
                scalar lb = biv - seiv*invttail(e(df_r),alpha/2)
                scalar ub = biv + seiv*invttail(e(df_r),alpha/2)
                scalar pvr = slope<ub & slope>lb
    
            post ‘sim’ (b) (biv) (se) (seiv) (pv) (pvr)
            }
        }
        postclose ‘sim’
    end
    
    regIV
    use results, clear
    summarize

  • #2

    ’ should be '
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks for your reply which solved the issue!

      Comment

      Working...
      X