GMACRO Psych #all macros must begin with the command GMACRO. The 2nd line is always a title for the macro #The next two lines clear all data from the first three columns of the worksheet, #and name the 3rd column (where the results of the simulations will be stored). erase c1 c2 c3 name c3 'successes in treatment group' #Everything that follows a NOTE command will be printed as text in the session window as the macro is running. NOTE NOTE Simulation of a Controlled Experiment with a Binary Outcome NOTE NOTE At the 'DATA>' prompt below, enter the number of times to repeat the NOTE simulation: #The next 4 lines get input from the user. The user inputs one value (nobs 1) at the keyboard (file "terminal") #in repsonse to the question above. The value entered is stored in column c100 and then copied from column c100 #to constant k1. set c100; file "terminal"; nobs 1. copy c100 k1 #The user is prompted for a second value, which is then stored as constant k2. NOTE NOTE Now enter the total number of subjects in the experiment: set c100; file "terminal"; nobs 1. copy c100 k2 #The user is prompted for a third value which is stored as constant k3. NOTE NOTE How many total successes were there in the experiment? set c100; file "terminal"; nobs 1. copy c100 k3 #The user is prompted for a fourth value which is stored as constant k4. NOTE NOTE How many subjects should be randomly assigned to the treatment group? NOTE set c100; file "terminal"; nobs 1. copy c100 k4 #Recall that k2 is the total number of subjects in the experiment, and k3 is the number of #successes in the experiment. Minitab now computes the number of failures in the experiment #and stores this value as k5. let k5=k2-k3 #Minitab now puts data in column 1. k3(1) tells Minitab to repeat the value "1" k3 times in column c1. #This is then followed by the value "0" repeated k5 times. That is, Minitab puts a 1 in column c1 for #each success and a 0 in column 1 for each failure. Each subject in the experiment is now represented #either by a 0 (failure) or 1 (success) in column c1. There are a total of k2 entries in column c1, #one for each subject. set c1 k3(1) k5(0) end #Now we conduct thee actual simulation. It will be repeated a total of k1 times. In each repetition, #k4 subjects are randomly selected from column c1 and listed in column c2. Recall that k4 is simply #the number of subjects in the treatment group, so column c2 now represents the subjects selected for #the treatment group. We then count the number of successes in the treatment group, which can be done #by simply adding up column c2 since each success is a 1 and each failure is a 0. Finally, this result #is stored in column c3. k6 is a counter which keeps track of which repetition the simulation is on. #During the first repetition, k6=1; during the second, k6=2; and so on. The c3(k6) in the #second to last line below tells Minitab to store the results of repetition k6 in row k6 of column c3. do k6=1:k1 sample k4 c1 c2; noreplace. let c3(k6)=sum(c2) enddo #Finally, the results of the simulation are tallied up in a table which will be outputed in the #session window. The table will include the number of times that each outcome occurred as well #as the percentage of the time each outcome occurred. tally c3; counts; percents. #All macros must end with ENDMACRO. ENDMACRO