Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: -alpha-, unexpected behavior

From   Barth Riley <[email protected]>
To   [email protected]
Subject   Re: st: -alpha-, unexpected behavior
Date   Fri, 23 Mar 2012 00:08:33 -0500

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?


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 "";, 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'

//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)
//- sum `scm'
//= sum __000001

What's going on?


*   For searches and help try:

*   For searches and help try:

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