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]

Re: st: -alpha-, unexpected behavior


From   Joerg Luedicke <[email protected]>
To   [email protected]
Subject   Re: st: -alpha-, unexpected behavior
Date   Fri, 23 Mar 2012 06:51:49 -0700

Thanks, Nick and Barth. I was assuming that -marksample- only marks
out observations
corresponding to specifications with -if- and -in-. I should have read
the documentation
more carefully!

Thanks again,

Joerg

On Fri, Mar 23, 2012 at 1:59 AM, Nick Cox <[email protected]> wrote:
> -marksample- still has the important role of paying attention to -if-
> and -in- when specified.
>
> On Fri, Mar 23, 2012 at 5:08 AM, Barth Riley <[email protected]> wrote:
>> According to the marksample help documentation:
>>
>>    5.  The marker variable is set to 0 in observations for which any of the
>>        numeric variables in varlist contain a numeric missing value.
>>
>>
>> So my interpretation is that if any of the variables in varlist of your
>> program have a numeric missing value, marker is set to 0 regardless of the
>> value of minim. I am not sure what purpose the marksample command provides
>> in your code--what happens if you were to remove it?
>>
>> Barth
>>
>>
>>
>> On 3/22/2012 11:10 PM, Joerg Luedicke wrote:
>>>
>>> Hi everyone!
>>>
>>> I am puzzled by something related to Stata's -alpha-, a program
>>> which, for example, calculates Cronbach's alpha or can be used to
>>> create a variable that holds the arithmetic mean of some other variables.
>>> I am puzzled because when wrapping -alpha- into some program, it
>>> does not behave as expected.
>>>
>>> //To illustrate the problem, let's first get some toy data:
>>> use "http://www.stata-press.com/data/r11/bg2";, clear
>>>
>>> //and create 100 missing values:
>>> replace bg2cost1=. in 1/100
>>>
>>> //Now we run -alpha- and generate mean scales:
>>> alpha bg2cost1 bg2cost2 bg2cost3 bg2cost4, asis g(v1) // a)
>>> alpha bg2cost1 bg2cost2 bg2cost3 bg2cost4, asis min(1) g(v2) // b)
>>> alpha bg2cost1 bg2cost2 bg2cost3 bg2cost4, asis casewise g(v3) // c)
>>>
>>> //-alpha-'s default is to average over items when at least one item
>>> //has non-missing values (see a) and b) above). If you want a listwise
>>> //deletion, i.e. only take the mean in case all variables have non-
>>> //missing values, you have to make use of the option -casewise- (c).
>>> //So a) and b) yield mean scores for n=568 cases, whereas c)
>>> //yields means for only n=468, just as expected:
>>>
>>> sum v*
>>>
>>>
>>>     Variable |       Obs        Mean    Std. Dev.       Min        Max
>>> -------------+--------------------------------------------------------
>>>           v1 |       568   -.0005873    .6138736  -2.163204   1.703003
>>>           v2 |       568   -.0005873    .6138736  -2.163204   1.703003
>>>           v3 |       468   -.0092219    .5812742  -1.743957   1.703003
>>>
>>>
>>> //Now consider the following little toy program in which we pass some
>>> stuff
>>> //to -alpha- inside the program, let -alpha- create a temporary
>>> //variable, and finally show a summary of the created variable:
>>>
>>> program define foo66
>>> version 11.2
>>>
>>>        syntax varlist [if] [in] [, minim(integer 1) Generate(string) ]
>>>
>>>        marksample touse
>>>
>>>        tempvar scm
>>>        qui alpha `varlist' if `touse', min(`minim') asis g(`scm')
>>>        di in red `minim'
>>>        sum `scm'
>>>
>>> end
>>>
>>> //Running the toy program with the default value of min=1, just as
>>> //in b):
>>> foo66 bg2cost1 bg2cost2 bg2cost3 bg2cost4
>>>
>>> //yields means for n=468, i.e. results in a listwise deletion of the 100
>>> cases,
>>> //even though we told -alpha- that only one variable would be sufficient
>>> //to calculate the mean. This is _not_ as expected:
>>>
>>>     Variable |       Obs        Mean    Std. Dev.       Min        Max
>>> -------------+--------------------------------------------------------
>>>     __000001 |       468   -.0092219    .5812742  -1.743957   1.703003
>>>
>>>
>>> //Inspecting the trace, everything seems to get picked up correctly:
>>> //- qui alpha `varlist' if `touse', min(`minim') asis g(`scm')
>>> //= qui alpha bg2cost1 bg2cost2 bg2cost3 bg2cost4 if __000000, min(1)
>>> asis g(__000001)
>>> *<snip>
>>> //- sum `scm'
>>> //= sum __000001
>>>
>>> What's going on?
>>>
>>> Cheers,
>>>
>>> Joerg
>>> *
>>> *   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/
>>>
>> *
>> *   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/
>
> *
> *   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/

*
*   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