Announcement

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

  • commands within curly braces is being ignored

    Hi, I have the following code where my regressions work just fine as a standalone, but when I add a condition that, in order to run the regression it must meet the criteria of a 31 day window (which is intentional and we know works for many cases), then the commands in the curly braces doesnt actually execute:

    * Run the regressions
    noisily{
    if r(max)==31{
    reghdfe shortinterest_adr ib0.windowcount#year [aweight = yearlymarketcap], abs(isinn) vce(cl isinn) nocons
    mat = r(table)
    matrix tmp = r(table)[1..2, "17.windowcount#2007.year".."17.windowcount#2019.y ear"]
    }
    }

    mat tmp=tmp'
    clear
    svmat tmp, names(col)
    gen year=_n+2006
    gen lb=b-1.96*se
    gen ub=b+1.96*se

    I know it doesn't execute because when I try to transpose my tmp matrix, I get the error "tmp not found". I've tried to even add intentional breaks, such as putting xxx after my regression line, and it doesn't break, whereas it should say "command xxx is unrecognised". Not sure why this is an issue as we had this running just fine previously. Does anyone have thoughts on this?

    Thanks!

  • #2
    The presumption here is that r(max) is accessible as returned by some previous command. If that isn't true r(max) will be evaluated as missing and so is not equal to 31. Hence your code is legal but Stata will not execute the braced-off code.

    In my current Stata session, no r-class results are visible, but it's not an error to refer to them.

    Code:
    . ret li
    
    . di r(max)
    .
    
    . di (r(max) == 31)
    0
    So which previous command that you don't show left r(max) in its wake?

    Comment


    • #3
      I'm hoping I understand your question correctly, but what we are doing is an event study, where we have periods of time where dividends are paid out. we want to evaluate the coefficients for our independent variable and graphically represent the 17th day coefficient. we use r(max)==31 because we dont want to run the regression in circumstances where the data simply isn't available for that entire window (i.e. smaller countries may not have a full window of data) so we only want to evaluate where there's a full set of coefficients (otherwise this drives a whole host of other errors due to missing data. The thought process here is that especially in certain years, or with certain countries, short interest_adr has not, or can not be calculated for each of the 31 days. Here's that section of the code:

      local countries "aut che deu dnk esp fin fra gbr irl ita nld nor prt swe"

      foreach now in `countries' {
      use "/Users/davidmurphy/Dropbox/cum_fake_data/dataforanalysis/dataforanalysis_`now'_120423.dta", clear
      di "analysis"
      run "/Users/davidmurphy/Dropbox/cum_fake_data/frag_country_analysis_adr5.do"
      graph export "/Users/davidmurphy/Dropbox/cum_fake_data/yearly_output/_shortinterest_adr_`now'_yearly_event_study.png", replace
      }

      This kicks off the code I previously submitted.

      Let me know if I missed the mark on your question but I hope this helps clarify

      Comment


      • #4
        Sorry I should add, sometimes, stata simply shows this, which is another confirmation that nothing is being done from the master command I just showed.

        . noisily{
        . if r(max)==31{
        . reghdfe shortinterest_adr ib0.windowcount#year [aweight = yearlymarketcap], abs(isinn) vce(cl isinn) nocons
        . xxx
        . mat = r(table)
        . matrix tmp = r(table)[1..2, "17.windowcount#2007.year".."17.windowcount#20 19.y ear"]
        . }
        . }

        .
        end of do-file

        Notice, we SHOULD see a break after the regression, and yet there is no break

        Comment


        • #5
          Thanks for the detail, but my question remains, and I will restate it. Which command leaves r(max) in its wake? Perhaps something inside your do-file runs something that is r-class, but you don't show the file or explain what it does. How do you think that Stata calculated r(max)? It could for example be left behind by some summarize command, but not indefinitely.

          Comment


          • #6
            My apologies, I am trying to make sure I understand the term it its wake, correctly. I believe the answer to your question would be the coefficients, standard errors, and year.

            Comment


            • #7
              That's not an answer, because I've asked twice for information on the command that produced r(max). Sorry, but I can't even try to help more here without the information I've asked for.

              (The expression in its wake is just a metaphor here for what is left behind after something has gone by. It's not a Stata term. Perhaps your first language is not English, contrary to my guess from your name.)
              Last edited by Nick Cox; 01 Sep 2023, 04:48.

              Comment

              Working...
              X