4
$\begingroup$

I am trying to estimate the mean of a variable for 2 different groups. If in Stata I use

. bys group: sum variable 

I'll get the mean. However, there are differences among two groups in terms of age, gender, education... And I have to control for that. To be more clear, let's say my groups are immigrants and natives. I can get the mean by using

. sum variable if immigrants==1 
. sum variable if immigrant==0 

However, the characteristics of the two groups are different, i.e. immigrants are younger, less educated, etc. Hence, the difference between simple means across groups can be a result of being a immigrant but can also be because of different characteristics. Therefore, I have to control for the group characteristics among natives and immigrants. One way to do that is using matching immigrants with natives with similar characteristics. Then, I calculate the mean for immigrants and similar natives. I was wondering if there is another way of doing this without using any matching methods but with some simple Stata commands.

$\endgroup$
0

2 Answers 2

3
$\begingroup$

Example illustrated with auto data in Stata

# without controls and if you want to find the mean of variable say price for foreign, where foreign consists of two groups (if foreign==0, domestic, and if foreign==1, it is Foreign).

sysuse auto, clear

Two ways:

1. Use linear reg (for simplicity I am assuming linearity in variables)

reg  price  foreign

      Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  1,    72) =    0.17
       Model |  1507382.66     1  1507382.66           Prob > F      =  0.6802
    Residual |   633558013    72  8799416.85           R-squared     =  0.0024
-------------+------------------------------           Adj R-squared = -0.0115
       Total |   635065396    73  8699525.97           Root MSE      =  2966.4

------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     foreign |   312.2587   754.4488     0.41   0.680    -1191.708    1816.225
       _cons |   6072.423    411.363    14.76   0.000     5252.386     6892.46
------------------------------------------------------------------------------

2: use by price

 by foreign: sum price

-------------------------------------------------------------------------------------------------------------------
-> foreign = Domestic

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       price |        52    6072.423    3097.104       3291      15906

-------------------------------------------------------------------------------------------------------------------
-> foreign = Foreign

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       price |        22    6384.682    2621.915       3748      12990

If you compare two methods, you see that intercept in the first approach gives the mean price when foreign is domestic and coefficient on foreign plus the intercept gives the mean price for Foreign when foreign is Foreign.

# Now if you want to control other variables, there is only one way you can do that (of course there is matching which you already mentioned). You need to use linear regression (again for simplicity, I am assuming linearity in all variables). Say, you want to control for weight and length

reg  price  foreign weight length

      Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  3,    70) =   28.39
       Model |   348565467     3   116188489           Prob > F      =  0.0000
    Residual |   286499930    70  4092856.14           R-squared     =  0.5489
-------------+------------------------------           Adj R-squared =  0.5295
       Total |   635065396    73  8699525.97           Root MSE      =  2023.1

------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     foreign |   3573.092    639.328     5.59   0.000     2297.992    4848.191
      weight |   5.774712   .9594168     6.02   0.000     3.861215    7.688208
      length |  -91.37083   32.82833    -2.78   0.007    -156.8449   -25.89679
       _cons |   4838.021    3742.01     1.29   0.200    -2625.183    12301.22
-----------------------------------------------

Now the intercept gives the mean price for domestic after controlling for length and weight and intercept plus coefficient on Foreign gives the mean price for Foreign after controlling for length and weight.

.

$\endgroup$
5
$\begingroup$

Once you control for a variable, it doesn't have a mean any more.

Say I have a group of kids, I can estimate their mean height.

But then I say "What's their mean height, controlling for age". There is no longer a mean. Because the height depends on the age, so the question is, "at what age".

You use regression, and you can get the gender (say) difference in the heights, controlling for age (making a bunch of assumptions). In Stata that would be:

reg height age gender

The estimate associated with gender is the difference in the heights, controlling for age.

$\endgroup$
1
  • 2
    $\begingroup$ To expand on Jeremy's answer- either you match the other variable, or you build a model eg linear regression, where you have to decide if height is a linear function of age, or more complicated. then you can look at the differnces in your groups having subtracted the predicted value based on the irrelevant variables.. $\endgroup$
    – seanv507
    Commented Aug 6, 2013 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.