Announcement

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

  • event study code receive invalid syntax when using "reg ret"

    Hi!
    I´m conducting an event study using the following code, however, I´m getting invalid syntax for the "reg ret" command. We are using data for 162 companies' stock prices over ten days and an estimation window of 100 days.
    This is our code:
    clear

    cd "U:\Downloads\masterthesis"

    import excel "cuppsatsnyversion", clear first

    destring _all, force replace

    foreach var of varlist _all {

    cap rename `var' `=substr("`var'", 1, 10)'

    }



    drop CANADAGOOSEHDGNYSSBNTDVT SILVANOFASHGROUPWARU FOOTWAYGROUPPFSHSU GENTILIU GMLEATHERS GROUNDEDPE

    rename _all price=

    rename priceName date



    * Reshape the dataset to long format

    reshape long price, i(date) j(company) string

    sort company date



    * Create a unique identifier for each company and set the panel structure

    by company: gen datenum = _n



    by company: gen target = datenum if date==22825

    egen td = min(target), by(company)

    drop target



    gen dif = datenum-td



    by company: gen event_window = 1 if dif > -10 & dif < 10



    egen count_event_obs = count(event_window), by(company)



    by company: gen estimation_window = 1 if dif < -10 & dif > -100



    egen count_est_obs = count(estimation_window), by(company)

    replace event_window = 0 if event_window == .

    replace estimation_window = 0 if estimation_window == .



    tab company if count_event_obs < 5

    tab company if count_est_obs < 30



    gen predicted_return = .


    su company, meanonly

    reg ret market_return if id==`i' & estimation_window==1
    predict p if id==`i'
    replace predicted_return = p if id==`i' & event_window==1
    drop p}


    Regards,
    Esther

    Attached Files

  • #2
    Where do you define local macro i ?

    Comment


    • #3
      I see now that we have not done that, what command can I use to do that?

      Comment


      • #4
        I guess you’re copying from somewhere. If you look at your source it should include a loop over companies.

        Comment


        • #5
          yes we used the code from this paper, but we can´t find anything that we missed. https://www.sciencedirect.com/scienc...19850121000328

          Comment


          • #6
            At a quick glance the paper does not include this crucial code detail.

            The authors seem to be copying from elsewhere any way. I am not impressed that the program name Stata is rendered as STATA, a small sign but one implying a lack of deep familiarity with the software.

            Also worrying: where does the variable id come from?

            The last few lines would be better as

            Code:
            gen predicted_return = .
            
            egen id = group(company) 
            su id, meanonly 
            
            forval i = 1/`r(max)' { 
            
            reg ret market_return if id==`i' & estimation_window==1
            predict p if id==`i'
            replace predicted_return = p if id==`i' & event_window==1
            drop p
            
            }

            Comment


            • #7
              Thank you! We tried using this code but “ret “ was not found. Have we missed something else?

              Comment


              • #8
                As I hope is clear, I am not trying to supply you with complete and correct code and I haven't read all the paper concerned.

                The code you are trying to implement refers not only to ret but also to market_return and if neither of those is a variable in your dataset, the command will fail utterly.

                I don't know whether the paper's code fragments are even consistent. It could be that you have changed some variable names but not all to match your data.

                It seems to me that you need a better model to emulate. Even if you can get the code to work (namely produce results) your strategy is risky because it is based on copying code but not fully understanding it.

                Comment


                • #9
                  Wow, that's a horrible paper. It seems mostly to have been scraped from the Princeton website (https://libguides.princeton.edu/eventstudy), with only a single footnote as acknowledgment; and then proceeds to present the code in a really clunky tabular formatting style that's almost impossible to copy-and-paste, and with inconsistent indentation. A rookie Stata user, unfamiliar with quirks such as the need to run an entire section of code at once to avoid local macro errors, would be stumped almost immediately!

                  Even the Princeton page has issues -- at one point they switch without warning from proper code to "pseudocode", where you're supposed to fill in the gaps yourself -- and at first glance I'm not even sure if it's correct (why should the "number of days in event window" be equal to the total number of observations, as suggested by use of tab event_date ?)

                  Best of luck, Esther... :-/

                  One thing I will say, going back to the OP, is that reg ret is not a "command". reg is short for regress, which is a command. ret is the dependent variable, which in the Princeton example was present in the original dataset. So you would need to make sure that you have an equivalent variable in your own dataset, to use as the dependent variable in your regression once you have prepared the data.

                  Comment


                  • #10
                    Just to say that I agree with David Fisher from what I've read.

                    Cox's Seventh Law says: Distrust any source that can't even spell the software name in the approved fashion.

                    That isn't pedantry, it's sociology.

                    Comment

                    Working...
                    X