Announcement

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

  • simulation not working (running only once)

    Hi, Stata people. I am really sorry to post this again. I am assigning random treatment and then want to run the regression 1000 times. However, now my regression is only running for once..

    Please, Please help

    set more off
    set matsize 800


    cap program drop model
    set seed 6000
    set obs1280
    program model, rclass

    generate random=uniform()
    sort year random
    generate post=0
    replace post=1 in 1 in 1/29 // for year 2010
    replace post=1 in 296/337 // for year 2011
    replace post=1 in 578/619 // for year 2012


    reg wheat post i.country_id i.year i.country#c.line_time_trend [aw=ypop], cluster( country_id )


    return scalar tau_coeff = _b[post]
    return scalar tau_se = _se[post]
    return scalar r2 = e(r2)
    exit
    end

    simulate coeff=r(coeff) se=r(se) r2=r(r2), reps(1000): model


    sum





  • #2
    You don't show any output, but my guess is that Stata balks the second time it sees this line
    Code:
    generate random=uniform()
    And if you fix that, Stata will balk a moment later, when it reaches
    Code:
    generate post=0
    Try using temporary variables inside your program so that they aren't left lying around (as already defined variables) afterward.

    Also, what is the line
    Code:
    set obs1280
    supposed to be doing for what appears to be an already loaded dataset? And what's
    Code:
    exit
    end
    all about?

    You might want to look into your data-management and into the specification of your regression model, too: you're not controlling the sort order of country_id, and you don't include both main effects of the interaction term.

    Comment


    • #3
      Thanks for your reply, Joseph.

      Yes, I run this on an already loaded dataset. Generate random= uniform () and then I don't control the sort order of country id and main effects of the interaction term and random and years because I want to randomly assign treatment to the different no of observation treated in year n (where the no of the assignment in year n should be same as in the base dataset)

      The post is my treatment variable, so I am setting it to zero first and then assigning the treatment. How should I go about it ??
      Attached Files
      Last edited by Aditi Roy; 06 Nov 2019, 02:13.

      Comment

      Working...
      X