Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: RE: summing across bins


From   Lenna Nepomnyaschy <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: RE: summing across bins
Date   Mon, 13 Feb 2006 13:35:33 -0500 (EST)

Hi Nick,

using the binsm command with weights would solve all my problems. It would be so great if it were possible. I just downloaded it yesterday and it works beautifully otherwise.

Thanks,
Lenna


On Mon, 13 Feb 2006, Nick Cox wrote:


Also, on -binsm-: the latest public domain version is
1.1.0 for Stata 4 in STB-37.

I didn't know anyone ever used it.
I will see if an update can be done quickly.

Nick
[email protected]

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Cox
Sent: 13 February 2006 15:01
To: [email protected]
Subject: st: RE: RE: summing across bins


In addition to other comments, see

FAQ     . . Calculating variables containing weighted group
summary statistics
        . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
and S. P. Jenkins
        1/03    I want to calculate a variable containing weighted
                group summary statistics, but I do not want to
                collapse the data and egen does not support weights.
                How can I do this?
                http://www.stata.com/support/faqs/data/weighted.html

Nick
[email protected]

David Harrison

It is fairly simple to write a new subcommand for -egen- to do a
weighted mean...

*! DAH 1.0.0 13feb2006
program _gwmean
    version 8
    gettoken type 0 : 0
    gettoken vn 0 : 0
    gettoken eqs 0 : 0
    syntax varname(numeric) [if] [in] , Wvar(varname) [
BY(varlist) ]
    quietly {
        marksample touse
        bysort `touse' `by': gen `type' `vn' =
sum(`wvar'*`varlist')/sum(`wvar'*!missing(`varlist')) if `touse'==1
        by `touse' `by': replace `vn' = `vn'[_N]
    }
end

If you save the above as _gwmean.ado (in your ado path),
then you will
have access to a new egen subcommand -wmean()-. The
compulsory option
-wvar()- specifies the variable of weights.
Lenna Nepomnyaschy

I just downloaded the ado file binsm, which allows you to graph mean
values (or other values) of yvar on bins of xvar.  But, I
need to use
weights. Does anyone have another way to do this that allow weights?
the binsm command does not.

Alternatively, does anyone know how to create a variable
with weighted
means across various groups. the command

egen newvar=mean(oldvar), by(group)
does not allow weights.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


Lenna Nepomnyaschy
Post-Doctoral Fellow
Columbia University School of Social Work
1255 Amsterdam Ave, room 718
New York, NY 10027
Phone: (212) 851-2379
Fax: (212) 851-2377
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index