Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: -alpha-, unexpected behavior


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: -alpha-, unexpected behavior
Date   Fri, 23 Mar 2012 08:56:36 +0000

This question is a model question, explaining the problem clearly,
concisely, precisely and reproducibly!

Don't blame -alpha-. What is different inside your program is that
-marksample- is doing its job, including marking out observations with
missing values. -alpha- never gets allowed to exercise its indulgence.

For your purposes you want

marksample touse, novarlist

Nick

On Fri, Mar 23, 2012 at 4:10 AM, Joerg Luedicke
<joerg.luedicke@gmail.com> wrote:

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

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index