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

# re: st: calculating an average within group means with specific weights

 From Steve Samuels To statalist@hsphsun2.harvard.edu Subject re: st: calculating an average within group means with specific weights Date Wed, 9 Jan 2013 09:28:38 -0500

```Use the stdize() and stdweight() options of -mean-
**************************************************
sysuse auto, clear
tab foreign
recode rep78 1/2=3
mean trunk, over(rep78)

gen stdw = 20 if foreign==0
replace std = 80 if foreign==1
mean trunk, over(rep78) stdize(foreign) stdweight(stdw)
*****************************************************

Steve

On Tues, January 8, 2013 Jordan Nickerson <Jordan.Nickerson@phd.mccombs.utexas.edu> wrote:

>
> Hello,
>
> I've been scratching my head trying to figure this out all morning.
>
> I have a set of observations (call the variable of interest size) that can be segmented with 3 distinct variables (you can call them gender, state, and year). The ultimate goal will be to compute the average for each gender across years, while weighting appropriately for the proportion of all observations from a given state.
>
> As an example, suppose the % of the observations from different states are as follows: Texas = 50%, Ohio = 30%, Florida = 20%.
>
> I'm trying to find a robust way to calculate the mean (and SEs) of size for both genders in each year, after controlling for the state in the following way.
>
> Suppose the averages are as follows:
> Avg(Size | Male, Texas, 2000) = 20
> Avg(Size | Male, Ohio, 2000) = 30
> Avg(Size | Male, Florida, 2000) = 40
>
> The desired end result would be 20 * .5 + 30 * .3 + 40 * .2 = 27 for males in 2000
>
> I've tried mean size [fweight=X] if gender = "Male", over(year) for any possible permutation of X (% of obs per state, % of obs per state / % obs per state-year, and so on...)
>
> Is there something that I'm missing?
>
> Thanks
> Jordan

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```