Announcement

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

  • simulate an error

    Hello,
    I'm trying to do a simulation of 3 types of errors in stata. I have to create one that is E(e1|x)=0, another that is E(e2|x)=constant and E(e3|x)=0 with corrX,e3=0.2

    Till now I have this in the do file:
    set seed 10000
    set obs 10000

    g x = invnormal(uniform())
    sum x

    g e1 = invnormal(uniform())
    sum e1

    g e2 = invnormal(uniform()) + 1
    sum e2

    g e3 = invnormal(uniform())?????

    corr x e1
    corr x e2
    corr x e3

    I don't know how to do the third error,

    Thanks

  • #2
    Gabriel:
    welcome to this forum.
    Do you mean something along the following lines?
    Code:
    . set obs 1000
    number of observations (_N) was 0, now 1,000
    
    . matrix C = (1.0000, 0.2 \ 0.2, 1.0000)
    
    . drawnorm x e , corr(C)
    
    . correlate x e
    (obs=1,000)
    
                 |        x        e
    -------------+------------------
               x |   1.0000
               e |   0.1789   1.0000
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X