Announcement

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

  • heteroskedasticity simulation

    Hi there,
    I would like to run the following code:

    clear all
    program define mcsimul1, rclass
    version 10.0
    syntax [, c(real 1)]
    tempvar e1 e2
    gen double ‘e1’=invnorm(uniform())*‘c’*zmu
    gen double ‘e2’=invnorm(uniform())*‘c’*z_factor
    replace y1 = true_y + ‘e1’
    replace y2 = true_y + ‘e2’
    summ y1
    return scalar mu1 = r(mean)
    return scalar se_mu1 = r(sd)/sqrt(r(N))
    summ y2
    return scalar mu2 = r(mean)
    return scalar se_mu2 = r(sd)/sqrt(r(N))
    return scalar c = ‘c’
    end

    local reps 1000

    forv i=1/10 {
    qui webuse census2, clear
    gen true_y = age
    gen z_factor = region
    sum z_factor, meanonly
    scalar zmu = r(mean)
    qui {
    gen y1 = .
    gen y2 = .
    local c = ‘i’*10
    simulate c=r(c) mu1=r(mu1) se_mu1=r(se_mu1) ///
    mu2=r(mu2) se_mu2=r(se_mu2), ///
    saving(cc‘i’,replace) nodots reps(‘reps’): ///
    mcsimul1, c(‘c’)
    }
    }

    use cc1
    forv i=2/10 {
    append using cc‘i’
    }
    gen het_infl = se_mu2 / se_mu1
    save cc_1_10,replace

    tabstat mu1 se_mu1 mu2 se_mu2 het_infl, ///
    stat(mean) by(c)

    as described in slide 9-10 here http://fmwww.bc.edu/GStat/docs/StataSimul.pdf

    I have tried adjusting the ` ' signs on the code but there seems to be other issues. Could I get some help in running this?

    Many thanks
    Karen

  • #2
    The code runs without problem on my computer. Did you copy that code in your do-file editor, and than run the entire code and not line by line?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks Maarten. I tried running it all at once and also by sections. That's odd!
      Click image for larger version

Name:	Screenshot 2024-03-05 180750.png
Views:	1
Size:	38.4 KB
ID:	1745575

      Comment


      • #4
        Code:
        local c=`i' +10
        Pay attention to the left and right single quotes. These are a grave accent and an apostrophe, respectively. Perhaps you are copying the code to a word editor before copying to the do-file and this changes the characters.

        Comment

        Working...
        X