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]
Re: st: Permute - error message
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Permute - error message
Date
Thu, 31 Mar 2011 13:28:08 +0100
I don't know what error messages you are getting. You don't tell us
and what I did, as below, ran without error.
The first thing I noticed was that your code can be slimmed down. It
seems to me that
> 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
is equivalent to
egen mean = rowmean(y1-y10)
cap program drop mydiff
program mydiff, rclass
su mean if z == 1, meanonly
local mean_treat = r(mean)
su mean if z == 0, meanonly
return scalar diff = `mean_treat' - r(mean)
end
I am a big fan of -egen- when appropriate, but egenitis is a condition
in which it is used quite unnecessarily to create variables merely to
hold single constants.
When I ran that I got output with -permute-.
That said, I don't think that I what I did was anything other than
making style changes, so I can't explain your report of errors.
Nick
On Thu, Mar 31, 2011 at 11:40 AM, Guy Grossman <[email protected]> wrote:
> 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/