Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mean of Means by Mutliple Groups

    Hi all,

    I'm trying to calculate the mean of subgroups that additionally fulfill a certain condition: Specifically, I'd like to calculate the mean market cap by month of all firms that are IPO firms (i.e. IPO dummy ==1). What I tried is this:

    Code:
    bysort Month IPOdummy1Y: egen MeanMC1Y = mean(realmarketcap)
    This somehow changes my values I have stored in IPOdummy1Y. Can someone kindly explain why this happens and how I could avoid this?

    Many thanks for your help.

    Best,
    Peter

  • #2
    I cannot see how this would change the values in IPOdummy1Y. But, it can/will change the sort order. Please show an example of your data (and/or summary statistics before and after the creation of the mean variable). Use the -dataex- (see FAQ 12.2).
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      I can assure you that the command you have shown does not change the values in iPodummy1Y, although it does sort the observations in your dataset into order by Month and within each month, by IPOdummy1Y, but does not sort by firm. Perhaps the different order of your data has misled you, or perhaps some other command replaced values in IPOdummy1Y.

      The egen command creates a new variable MeanMC1Y which, for each observation, will be the mean of all realmarketcap for all observations in the same Month with the same value for IPOdummy1Y.

      If you still believe IPOdummy1Y values were changed, you'll need to post an example, with before-and-after values, and the code and results of all commands between the before and after.

      Comment


      • #4
        Dear William and Carole, thanks so much for your inputs. You're absolutely right, the command did not change values but the order and this ordering misled me. Post-calculating means, I wanted to count the number of IPO firms and my command was:

        Code:
        by cusip, sort: gen nvals = _n == 1 if IPOdummy1Y == 1
        count if nvals == 1
        This led to a new value after the egen command. Now, I amended the command to this and arrive at the same number of firms:

        Code:
        by cusip IPOdummy1Y, sort: gen nvals = _n == 1 if IPOdummy1Y == 1
        count if nvals == 1
        Again, many thanks for your quick and extensive help - very useful.

        Best,
        Peter

        Comment

        Working...
        X