Announcement

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

  • 1000 times simulation with random treatment for different y variables


    I want to randomly assign treatment to others in the same year and then simulate it for 1000 times for all my y variables. I want the coefficient, standard error, and the confidence interval.


    I am running the following code but STATA is issuing "varlist not allowed" after program NO treatment - Copy, rclass. Any help is appreciated. I am not sure if I am coding it correctly


    drop random
    drop post
    set more off
    set matsize 800


    cap program drop NO treatment - Copy
    set seed 6000
    program NO treatment - Copy, rclass


    unab y : wheat rice lentils
    local l : word count `y'

    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

    foreach var of local y {
    quietly reg `var' 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]
    end

    simulate post= r(post)
    tau_coeff = r(tau_coeff) ///
    tau_se = r(tau_se) , reps(1000) saving(NO treatment - Copy.dta, replace): NO treatment - Copy

    sum
    Last edited by Aditi Roy; 05 Nov 2019, 18:03.

  • #2
    Duplicate post -- asked and answered at https://www.statalist.org/forums/for...ndom-variables

    Bumping is strongly discouraged here. First of all, your two posts are only a few minutes apart. Patience is a virtue. Second, if you post a question and do not get a response after a day, reposting the same question is unlikely to help you. If nobody has answered your question it is likely because it is unclear, or on an obscure topic that nobody else here knows about. So it is usually a good idea to try to think hard about why you didn't get an answer and then modify your question accordingly.

    Comment

    Working...
    X