Announcement

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

  • Random sample without replacement

    Hi everyone, I am looking to select a random set of treatment states (iterating i+1 each time) within a my exterior loop, but without replacement so that I do not select the same random state twice. Does anyone know how to do that? See code below!
    Code:
    clear 
    set seed 1234
    
    //1 - difference-in-differences Monte Carlo//
    
    set obs 1000
    
    gen state =.
    gen year =. 
    
    
    //Setting state proportional to population//
    local inc_1=1
    foreach i in 0 120 210 270 330 370 410 440 470 500 530 560 580 600 620 640 660 680 700 720 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 965 970 975 980 985 990 995 {
        
        replace state = `inc_1' if _n > `i'
        
        local inc_1 = `inc_1' + 1
        
    }
    
    
    //setting year//
    local inc_2=1
    forvalues i = 0(100)1000 {
        
        replace year = `inc_2' if _n > `i'
        
        local inc_2 = `inc_2' + 1
    }
    
    expand 10
    
    //generating data//
    
    gen y = rnormal()
    
    gen treat = 0
    gen post = 0
    
    
    mata: pvals = J(1000,49,.)
    
    forvalues i = 1/49 {
        
        local inc_3 = i
        
        forvalues i_2 = 1/1000 {
            
            
            replace post = 1 if year >= floor((4)*runiform() + 4)
            
            
            
            
    
    
            
            
        }
    
        
        
    }
Working...
X