Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Permute - error message


From   Guy Grossman <[email protected]>
To   [email protected]
Subject   st: Permute - error message
Date   Thu, 31 Mar 2011 06:40:20 -0400

Dear friends,

I am trying to conduct a simple randomization inference analysis
(permuting Z - treatment indicator). y1-y10 are outcomes of individual
units within groups identified by the id variable. The number of units
within groups varies from 3 to 10. In the original data 3 groups are
treated (z=1) and 5 are control (z=0).

For some reason whether I am using the permute command or the
user-written "tsrtest" command (by Kaiser and Lacy) I get error
messages which I fail to correct. Any suggestions on how to get this
code running would be highly appreciated.

Thanks!
Guy

input id z y1 y2 y3 y4 y5 y6 y7 y8 y9 y10
1 0 0 0 0 0 0 . . . . .
2 0 0 0 0 0 0 0 0 0 0 0
3 0 1 1 1 1 0 . . . . .
4 0 0 1 1 . . . . . . .
5 1 0 0 1 1 . . . . . .
6 1 1 1 1 1 1 . . . . .
7 0 0 0 0 1 0 0 . . . .
8 1 0 0 0 1 0 1 . . . .
end

egen grouptotal = rowtotal(y1-y10)
egen groupN = rownonmiss(y1-y10)

cap program drop mydiff
program define mydiff, rclass
       egen tot_treat = total(grouptotal) if z ==1
       egen tot_cont = total(grouptotal) if z ==0
       egen N_treat = total(groupN) if z ==1
       egen N_cont = total(groupN) if z ==0
       sum tot_treat
       local size_treat=r(max)
       sum tot_cont
       local size_cont=r(max)
       sum N_treat
       local N_treatment=r(max)
       sum N_cont
       local N_control=r(max)
       return scalar diff =
(`size_treat'/`N_treatment')-(`size_cont'/`N_control')
end
tsrtest z r(diff): mydiff
permute z r(diff): mydiff

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index