Announcement

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

  • Assigning Sectors to Companies for S&P500

    Good afternoon,

    I have a list of all of the companies within the S&P 500 on a file within Stata. Does anyone know if it is possible to add a new column to assign the relevant sector to each company?
    I do not have the sectors within my current dataset but I was wondering if you could bring it in somehow?

    Kind regards,
    Derick

  • #2
    This web page hosts a list: https://www.liberatedstocktrader.com...or-market-cap/, updated as of Jan 2023.

    You can consider using readhtml to scrape it:

    Code:
    net install readhtml, from(https://ssc.wisc.edu/sscc/stata/)
    readhtmltable https://www.liberatedstocktrader.com/sp-500-companies-list-by-sector-market-cap/, varname
    keep Ticker-PE_Ratio
    Sample results:

    Code:
         +-----------------------------------------------------------------------------------------------------+
         | Ticker                    Company                  Sector          Market_Capitalization   PE_Ratio |
         |-----------------------------------------------------------------------------------------------------|
      1. |    MRO   Marathon Oil Corporation         Energy Minerals                 17,388,156,106   2262.602 |
      2. |     MO         Altria Group, Inc.   Consumer Non-Durables                 81,364,639,112   522.1622 |
      3. |   ANET      Arista Networks, Inc.   Electronic Technology                 35,807,001,092   471.4286 |
      4. |    MTB   M&T Bank Corporation                 Finance                 25,831,948,062   397.9184 |
      5. |     CI          Cigna Corporation         Health Services                 94,846,357,195   332.8684 |
         +-----------------------------------------------------------------------------------------------------+
    They have 19 sectors, though... May need some re-grouping or you may have to scrape another site.
    Last edited by Ken Chui; 07 Mar 2023, 07:17.

    Comment

    Working...
    X