Announcement

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

  • Creating a new variable using percentage in a stratified randomisation

    Hi all,

    I am trying to create a new variable while doing a stratified randomisation. Please help.

    I want a new variable 'selected' which will take the first 60% of the rank as selected=1. I basically need 60% student of each class to be selected for the treatment (50% male and 50% female).The code I was using previously created rank for each school and I was taking 15 students regardless of class size.Gen_stu is the variable for gender and Types_Student=3 means co-education school where we have both male and female students.

    Please note each school has student of only one grade so when I created rank by School_ID I am giving a rank to each student in the class.

    My codes are:
    clear

    local seeds "482321 128828"


    foreach X of local seeds{
    set seed `X'
    use "C:\Users\Anika Zaman\Dropbox\IVR SSC\Stata\Upadated_dataset_IVR.dta" , replace
    joinby Record_ID using "C:\Users\Anika Zaman\Dropbox\IVR SSC\Stata\Student_Assessment_IVR.dta"
    merge m:1 School_ID using "C:\Users\Anika Zaman\Dropbox\IVR SSC\Stata\Final School listing survey(Version 3).dta"
    gen random=uniform()
    sort School_ID random
    bysort School_ID: gen rank=_n
    generate treated_student=1 if rank<=15
    replace treated_student=0 if rank>15
    bysort School_ID Gen_stu: gen rankbg=_n
    generate treated_student_b=1 if rankbg<=7 & Gen_stu==1 & Types_Student==3
    replace treated_student_b=0 if rankbg>7 & Gen_stu==1 & Types_Student==3
    generate treated_student_g=1 if rankbg<=7 & Gen_stu==2 & Types_Student==3
    replace treated_student_g=0 if rankbg>7 & Gen_stu==2 & Types_Student==3
    }

    Thank you.
Working...
X