Announcement

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

  • How to do a Monte Carlo simulation using Stata command?

    Hello Everyone,

    I would like to do a Monte Carlo simulation of the following process y_t using Stata command :
    Click image for larger version

Name:	process.PNG
Views:	1
Size:	23.0 KB
ID:	1487446



    Many thanks,

    Best,

  • #2
    Your description of the process is quite incomplete. You refer to distributions that are iid(0, sigma_squared), but you say nothing about what parametric form these distribution might take. In the code below illustrating the general approach, I use normal distributions.

    You also do not say how many i's and how many t's you want. I illustrate with 100 i's and 10 t's for each i.

    Also, you give recurrence formulas for r and z, but you do not provide initial conditions. In the illustrative code, the initial values are set to zero.

    Code:
    clear*
    set seed 1234
    
    local I 100
    local T 10
    
    local sig_alpha = sqrt(0.191)
    local sig_r = sqrt(0.004)
    local sig_z = sqrt(0.174)
    local rho = 0.645
    
    local r1 = 0
    local z1 = 0
    
    set obs `I'
    gen i = _n
    gen alpha = rnormal(0, `sig_alpha')
    expand `T'
    by i, sort: gen t = _n
    xtset i t
    
    by i (t), sort: gen r = `r1' if _n == 1
    by i (t): replace r = L1.r + rnormal(0, `sig_r') if _n > 1
    
    by i (t): gen z = `z1' if _n == 1
    by i (t): replace z = `rho' * L1.z + rnormal(0, `sig_z') if _n > 1
    
    gen y = alpha + r + z
    You can modify the code in ways that will make it conform to the values you actually want for those unspecified parameters.

    Comment


    • #3
      Dear Professor,

      Many thanks for your response,

      That's very useful!

      Best

      Comment

      Working...
      X