Announcement

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

  • Panel Data Help! Creating a Change Variabel

    Hello! This is my first post and very much in need of help with a project I've been working on for some time. I have a panel dataset for CEO campaign contributions, some company info, how much they donated to democrats in the 6 months prior to an election (midterm 2002 election), then _2002_ variable is the six month average stock price. Here is the dataex output, with the post variable corresponding to one of the two instances for each company for the 6 months pre/post the election date. I am trying to answer the question of how much an individual CEO donates to a campaign affects their stock price after an election - and for my regression I need a change variable for pre/post for _2002_, but have run into error when I run "by companyid: gen changestockprice = (_2002_ if post == 2) - (_2002 if post== 1)"

    Any help would be greatly appreciated !!! Thank you!!

    dataex:

    input str43 corpname str8 ticker float(companyid totaldem) double _2002_ byte post
    "Apple Inc" "AAPL" 1 2300 57.79999923706055 1
    "Apple Inc" "AAPL" 1 2300 51.54999923706055 2
    "Amerisourcebergen Corp" "ABC" 2 3667 54.5099983215332 1
    "Amerisourcebergen Corp" "ABC" 2 3667 48.90000152587891 2
    "Abbott Laboratories" "ABT" 3 15450 50.2599983215332 1
    "Abbott Laboratories" "ABT" 3 15450 43.65000152587891 2
    "Archer-Daniels-Midland Co" "ADM" 4 2000 53.54999923706055 1
    "Archer-Daniels-Midland Co" "ADM" 4 2000 49.7400016784668 2
    "Automatic Data Processing" "ADP" 5 700 51.54999923706055 1
    "Automatic Data Processing" "ADP" 5 700 59.47999954223633 2
    "Ameren" "AEE" 6 11450 53.23714229038784 1
    "Ameren" "AEE" 6 11450 48.370000566755024 2
    "American Electric Power Co Inc" "AEP" 7 28820 53.23714229038784 1
    "American Electric Power Co Inc" "AEP" 7 28820 15.5 2

    dataex (picture screengrab):


    Click image for larger version

Name:	Screen Shot 2023-02-26 at 7.57.51 PM.png
Views:	3
Size:	143.2 KB
ID:	1703548
    Attached Files

  • #2
    From your description, it sounds like you want

    Code:
    bys companyid (post): gen changestockprice = _2002_-_2002_[_n-1]

    Comment


    • #3
      Thank you so much that worked perfectly! Just to follow up on which kind of regression should be used, I was originally going to use "reg changestockprice totaldem i.companyid if post == 1, robust" but would I have to use areg since it is panel data? Also, with the missing values generated, should I drop my original instances of companies and leave the second that has a value for changestockprice? Just curious as to what would be the best regression to run to answer my question! Also is robust enough, or should I cluster on company?

      Very, very appreciative for your assistance!!!

      Comment

      Working...
      X