Announcement

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

  • Peer Firm Averages excluding ith observation

    Hi All,
    I am pretty new to Stata , so a bit lost on this one.
    I am trying to find Peer Firm averages of Mean , Median and St.Dev grouped by Industry (SIC code) but excluding the ith (firm specific observation)

    Any suggestions on how to approach this?

    Thank you in Advance

    Judith

  • #2
    Welcome!

    Please take a look of the FAQ here: https://www.statalist.org/forums/help. And pay attention on items 10-12 on how to craft an effective and efficient question, and then revise the current one by providing some example data and also more specific desired outcome. (For example, what is the condition of the i-th, etc.)

    Comment


    • #3
      Some of these problems are easy, but others benefit from focused code. The mean of others is at its simplest

      sum of others / (sample size MINUS 1)

      = (total of values MINUS this value) / (sample size MINUS 1)

      with a twist if missing values are present

      (total of values MINUS cond(missing(value), 0, value)) / (sample size MINUS !missing(value))

      More generally, consider commands such as
      rangestat (SSC). and asrol (SSC).

      Code:
      . webuse grunfeld, clear
      
      . sort year invest
      
      . rangestat (median) invest , int(year 0 0) excludeself
      
      . l invest invest_median if year == 1935
      
           +--------------------+
           | invest   invest_~n |
           |--------------------|
        1. |   2.54   33.099998 |
        2. |  12.93   33.099998 |
        3. |  20.36   33.099998 |
        4. |  24.43   33.099998 |
        5. |  26.63   33.099998 |
           |--------------------|
        6. |   33.1   26.629999 |
        7. |  39.68   26.629999 |
        8. |  40.29   26.629999 |
        9. |  209.9   26.629999 |
       10. |  317.6   26.629999 |
           +--------------------+

      Comment


      • #4
        Hi Ken Chui and Nick Cox
        Thank you for your help so far, I hope that this description is more precise

        Here is an example of the Data

        Click image for larger version

Name:	data.png
Views:	1
Size:	16.9 KB
ID:	1601645


        LPERMNO is the company code , each LPERMNO represents one firm,
        I want to group the observations by fyear and SIC_1 excluding the firms observation and get the averages of those groups' mean median and st.dev

        Output should look like this:
        Click image for larger version

Name:	Screenshot 2021-04-05 092933.png
Views:	2
Size:	27.6 KB
ID:	1601647


        Thank you,

        Judith
        Attached Files

        Comment


        • #5
          Thanks for updating the question. We unfortunately cannot copy and paste a screenshot onto Stata, it'd be wonderful if you can look into the package "dataex" and provide some actual data example. That way users here can provide you with tailored codes that you can immediately use.

          With the current first screenshot, I am still not sure if it illustrates what you need. Firm one has 8 data points, they are all under the same SIC 308, but their years are unique. Given that you said:

          I want to group the observations by fyear and SIC_1 excluding the firms observation and get the averages of those groups' mean median and st.dev
          1. You'll get the same data because the years are unique and hence there will be 8 year * 1 SIC combinations, which is still those 8 lines.
          2. There is no exclusion from the above description. When an individual-level data are aggregated into summary, we don't usually refer the individual data being "excluded," they were just expressed differently.
          Perhaps the next step would be i) if possible, check out dataex and provide us some sample data and ii) based on that data sample, tell us what you need summarized.

          Comment

          Working...
          X