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


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

st: RE: Find the mean of observations from a variable that satisfy a condition in another variable


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Find the mean of observations from a variable that satisfy a condition in another variable
Date   Fri, 12 Aug 2011 18:12:03 +0100

A stretched analogue is 

. sysuse auto, clear
(1978 Automobile Data)

. ttest mpg if rep78 == 4 | rep78 == 5, by(rep78)

Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
       4 |      18    21.66667     1.16316     4.93487    19.21261    24.12072
       5 |      11    27.36364    2.632913    8.732385    21.49714    33.23013
---------+--------------------------------------------------------------------
combined |      29    23.82759    1.312191    7.066364    21.13969    26.51549
---------+--------------------------------------------------------------------
    diff |            -5.69697    2.526323               -10.88056   -.5133831
------------------------------------------------------------------------------
    diff = mean(4) - mean(5)                                      t =  -2.2550
Ho: diff = 0                                     degrees of freedom =       27

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0162         Pr(|T| > |t|) = 0.0324          Pr(T > t) = 0.9838

Here there are two simple but useful tricks 

1. The -if- condition ensures precisely two groups are looked at. 

2. The -by()- option ensures a comparison between those groups. 

In your case, you should probably want to do something similar but with -xtreg-. Quite what different dependence assumptions apply with panel data is something to think about. 

N.B. A standard -ttest- can be done using -regress-: e.g. 

. gen mygroup = rep78 - 4 if rep78 > 3
(45 missing values generated)

. regress mpg mygroup

      Source |       SS       df       MS              Number of obs =      29
-------------+------------------------------           F(  1,    27) =    5.09
       Model |  221.592476     1  221.592476           Prob > F      =  0.0324
    Residual |  1176.54545    27  43.5757576           R-squared     =  0.1585
-------------+------------------------------           Adj R-squared =  0.1273
       Total |  1398.13793    28  49.9334975           Root MSE      =  6.6012

------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     mygroup |    5.69697   2.526323     2.26   0.032     .5133831    10.88056
       _cons |   21.66667   1.555916    13.93   0.000     18.47419    24.85914
------------------------------------------------------------------------------

. replace mygroup = -mygroup
(11 real changes made)

. regress mpg mygroup

      Source |       SS       df       MS              Number of obs =      29
-------------+------------------------------           F(  1,    27) =    5.09
       Model |  221.592476     1  221.592476           Prob > F      =  0.0324
    Residual |  1176.54545    27  43.5757576           R-squared     =  0.1585
-------------+------------------------------           Adj R-squared =  0.1273
       Total |  1398.13793    28  49.9334975           Root MSE      =  6.6012

------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     mygroup |   -5.69697   2.526323    -2.26   0.032    -10.88056   -.5133831
       _cons |   21.66667   1.555916    13.93   0.000     18.47419    24.85914
------------------------------------------------------------------------------

All that said, you want to do comparisons between three times, and quite what the underlying generating process is will determine the appropriate model to fit. I don't know what you know about equity issuance, and I can't advise. 

Nick 
n.j.cox@durham.ac.uk 

Islam Abdeljawad

I have panel data, two of my variables are equity issuance which is 0 if the firm did not issue equity in the year and 1 if it issue equity that year. the other variable is the leverage ratio. I want to find the mean leverage for firms that issue equity at the year of issuance, three years before the year of issuance and three years after the year of issuance. then test the hypothesis that the mean of leverage three years before and now are equal. also the leverage three years after issuance and now are equal (equality of means).
How to do it in stata.

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


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