Announcement

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

  • Mr

    Hi Stata members. I need quick help. i have a panel of firms that belong to different sectors of the economy. and i have returns for each firm. thus i have the following data
    firm month Sec Returns
    A 1 agric 20
    A 2 agric 21
    B 1 banking 15
    B 2 banking 10
    Now, i need to obtain sectoral mean for every month. help me with the code in stata

  • #2
    Well, in your example data, there is only one observation per sector per month, so there doesn't appear to be any reason to take a mean. But on the assumption that your real data there are multiple observations per sector per month, it would be:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str1 firm byte month str7 sec byte returns
    "A" 1 "agric"   20
    "A" 2 "agric"   21
    "B" 1 "banking" 15
    "B" 2 "banking" 10
    end
    
    
    by sec month, sort: egen mean_returns = mean(returns)
    In the future, when showing data examples, please use the -dataex- command to do so, as I have done in this response. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment

    Working...
    X