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   Thu, 22 Mar 2012 22:05:59 -0700

Oh boy, my -marksample- command is messing it up because it sets the
marker variable to 0 when there are
any missing values among the variables specified in `varlist'.

I had to write

-marksample touse, novarlist-

instead of
-marksample touse-

Nevermind!

Joerg




On Thu, Mar 22, 2012 at 9:10 PM, Joerg Luedicke
<[email protected]> 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/


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