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, is already up and running.

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

RE: st: means compairison with weights and unequal variance

From   Nick Cox <>
To   "''" <>
Subject   RE: st: means compairison with weights and unequal variance
Date   Mon, 21 Nov 2011 10:31:36 +0000

Describing -local-s as variables is very likely to confuse in any Stata context. Similarly, you are free to think of Stata variables as vectors or columns privately, but Stata has a separate syntax for vectors strict sense. 

See my postings earlier in the thread. 


Barbro Widerstedt

local is a _variable_ (a scalar value), while - gen- generates a new
column ( a vector of values)

r(N) is the number of observations in your data set (=a number) , if
you successfully - gen - you would violate the requirements of the
command, which is for scalar values.

On Mon, Nov 21, 2011 at 10:02 AM, David Ashcraft
<> wrote:
> John,
> I am trying to implement the code but replacing local with gen. Why I am not getting the same result, if I use gen rather than local?
> David
> ----- Original Message -----
> From: John Luke Gallup <>
> To:
> Cc:
> Sent: Monday, November 21, 2011 8:40:40 AM
> Subject: Re: st: means compairison with weights and unequal variance
> Barbro,
> A simple alternative is to calculate the means and standard deviations for each group using -summarize- with weights, and then run -ttesti ..., unequal-:
> sysuse auto, clear
> sum mpg if foreign [aw=weight]
> local N1 = r(N)
> local av1 = r(mean)
> local sd1 = r(sd)
> sum mpg if !foreign [aw=weight]
> local N2 = r(N)
> local av2 = r(mean)
> local sd2 = r(sd)
> ttesti `N1' `av1' `sd1' `N2' `av2' `sd2', unequal

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index