Announcement

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

  • Collapse different columns differently

    In a panel database of companies (bisnode), the revenue information is not always for the full year...sometimes it's quarterly, for example...

    So I want to collapse rows such that rows that belong to the same company for the same year are merged. Not just that, I want most columns to average out, but I 2 columns to aggregate (sum).

    Can I even run collapse such that it runs differently (average v sum) on different columns?
    Thank you for your help!

    Stata SE/17.0, Windows 10 Enterprise

  • #2
    Can I even run collapse such that it runs differently (average v sum) on different columns?
    Yes, you can, as is documented in the help file: https://www.stata.com/manuals13/dcollapse.pdf

    Starting with this example data:
    Code:
    clear
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(company year invest mvalue kstock time)
    1 1935 317.6 3078.5   2.8 1
    1 1936 391.8 4661.7  52.6 2
    1 1937 410.6 5387.1 156.9 3
    1 1938 257.7 2792.2 209.2 4
    1 1939 330.8 4313.2 203.4 5
    2 1935 209.9 1362.4  53.8 1
    2 1936 355.3 1807.1  50.5 2
    2 1937 469.9 2676.3 118.1 3
    2 1938 262.3 1801.9 260.2 4
    2 1939 230.4 1957.3 312.7 5
    end
    format %ty year
    And doing:
    Code:
    collapse (mean) invest (median) mvalue (sum) kstock, by(company)
    We end up with:
    Code:
    . list
    
         +------------------------------------+
         | company   invest   mvalue   kstock |
         |------------------------------------|
      1. |       1    341.7   4313.2    624.9 |
      2. |       2   305.56   1807.1    795.3 |
         +------------------------------------+
    As for your specific data, it is really not possible to understand what your data structure looks like based on your description.
    This is the reason the forum asks that you post a snippet of you data using dataex, see the FAQ: https://www.statalist.org/forums/help#stata

    Comment

    Working...
    X