Announcement

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

  • Need for a permutation test ?

    Hi, STATA people,

    I have 12000 observation. I want to randomly assign a fake treatment value of 1 to the variables but cap different number of treatments to different years.
    I want to cap
    29 variables in 1990
    42 variables in 1991
    57 variables in 1992

    To be more specific, of all the observations with year = YYYY, randomly assign some stipulated number of the observations to have the treatment variable set at 1, with the remainder set at 0."

    I want to repeatedly run my regression command 1000 times while randomly assigning the treatment variable within a year, but keeping the stipulated within-year distribution on the treatment variable. I want to see how my parameter estimates and so forth vary across this random shuffling of the treatment variable.

    I tried to simulate but STATA constantly issued --- " error in simulate". Given that I want to randomly shuffle assigning the treatment within years (by putting a cap) so I tried it with permute. However, the problem with permuting is it doesn't allow weights.

    I would like to ask if permute is suitable for such a situation and how to go about with the weights as weights are not allowed with permuting. I did try using expand but it didn't work.

    Your help is really appreciated

    Code:
    set matsize 8000, permanently
    set obs 12000
    set seed 8600
    generate random=uniform()
    gen byte treat= .
    sort year random
    by year: replace treat= (_n <=29) if (year == 1990)    
    by year: replace treat= (_n <=42) if (year == 1991)    
    by year: replace treat= (_n <=42) if (year == 1992)      
    permute treat bt = _b[treat] se = _se[treat] p_value = (2*ttail(e(df_r), abs(_b[treat]/_se[treat])))r2 = e(r2), ///  
    reps(1000) strata(year) saving("OutputFile.dta"): ///
    reg wheat treat i.country_id i.year i.country_id#c.line_time_trend [aw=ypop], cluster( country_id)      
    
    clear
    use "OutputFile.dta"
Working...
X