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: graph results of bitest stratified with by(var)
From
Richard Goldstein <[email protected]>
To
[email protected]
Subject
Re: st: graph results of bitest stratified with by(var)
Date
Thu, 23 Jan 2014 13:19:19 -0500
1. Michael, if you look at -h levelsof- there is an example showing its
use with -foreach-
2. Nick, I did not suggest -statsby- because Michael asked for something
that is not in the return list (r(k)/r(N)) and I don't think that this
is allowed with -statsby-, but maybe I'm wrong about that?
Rich
On 1/23/14, 1:07 PM, Nick Cox wrote:
> -search foreach- does exactly what you ask, namely point to sources on
> -foreach-.
>
> But -help statsby- does even better.
>
> Here's a dopey example.
>
> sysuse auto, clear
> statsby N=r(N) k=r(k) p_l=r(p_l) p_u=r(p_u) , by(rep78): bitest
> foreign=.2
> list
>
> Nick
> [email protected]
>
> On 23 January 2014 17:55, Michael McCulloch <[email protected]>
>
>> Thank you Richard, that's exactly what I'm wanting to achieve.
>> I understand now that -bysort- clears the scalars at each re-call.
>>
>> Can you point me to primers so I can learn how to wrap this into a -foreach- / -levelsof- loop?
>
>
> On Jan 23, 2014, at 5:45 AM, Richard Goldstein wrote:
>>
>>> If I understand what you want correctly, you cannot do it with bysort
>>> because each time you do the test the set of returned values (the
>>> "r()"'s) will be replaced and the old ones lost
>>>
>>> you can do this within a -foreach- loop (you may need -levelsof- first)
>>> in which you quietly do the -bitest- and then list your results for that
>>> test and then do the next -bitest-, etc.
>>>
>>> here is an example of how to use the returned values:
>>>
>>> . sysuse auto
>>>
>>> . bitest foreign=.2
>>>
>>> Variable | N Observed k Expected k Assumed p Observed p
>>> -------------+------------------------------------------------------------
>>> foreign | 74 22 14.8 0.20000 0.29730
>>>
>>> Pr(k >= 22) = 0.029904 (one-sided test)
>>> Pr(k <= 22) = 0.984075 (one-sided test)
>>> Pr(k <= 7 or k >= 22) = 0.041800 (two-sided test)
>>> r; t=0.09 8:39:38
>>>
>>> . di r(N) _skip(2) r(P_p) _skip(2) r(k)/r(N) _skip(2) r(p)
>>> 74 .2 .2972973 .04179963
>>>
>>> I have not put headers on the columns and have not done several other
>>> things you might want (e.g., print format for results) but this should
>>> give the basic idea, assuming I have correctly understood you
>
> On 1/23/14, 12:57 AM, Michael McCulloch wrote:
>
>>>> I am using bitest for a two-sided test on whether the mean of varB is different than 0.2, and testing on each level of varA:
>>>> bysort varA: bitest varB=.2
>>>>
>>>> varA has ~30 values. I wish to display these in a table (showing N, observed p,
>>> expected p, and the two-sided p-value), without manual cut-and-paste, as
>>> the test
>>> will be used to monitor an ongoing training program.
>>>>
>>>> I note that the results of bitest are stored as:
>>>> r(N) number N of trials
>>>> r(P_p) assumed probability p of success
>>>> r(k) observed number k of successes
>>>> r(p_l) lower one-sided p-value
>>>> r(p_u) upper one-sided p-value
>>>> r(p) two-sided p-value
>>>>
>>>> However, I do not know how one uses these r(**) values. Can anyone suggest how one
>>> would go about this?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/