Announcement

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

  • #16
    Getting closer. The problem, however, is that between those two, there is only one observation for any combination of CodeX and yearz. So there can be no firm-year regressions in this example. But you can get year cross-sectional regressions:

    Code:
    forvalues i = 1/4 {
        gen alpha`i' = .
        gen delta`i' = .
    }
    levelsof yearz, local(yereg)
    foreach y of local yereg {
        capture noisily reg E (i.D##c.R)##c.(SIZE LEV MTB)if yearz == `y'
        if c(rc) == 0 {
            replace alpha1 = _b[R] if yearz == `y'
            replace alpha2 = _b[c.R#c.SIZE] if yearz == `y'
            replace alpha3 = _b[c.R#c.MTB] if yearz == `y'
            replace alpha4 = _b[c.R#c.LEV] if yearz == `y'
             
            replace delta1 = _b[1.D#c.R] if yearz == `y'
            replace delta2 = _b[1.D#c.R#c.SIZE]  if yearz == `y'
            replace delta3 = _b[1.D#c.R#c.MTB]  if yearz == `y'
            replace delta4 = _b[1.D#c.R#c.LEV]  if yearz == `y'
        }
        else if inlist(c(rc), 2000, 2001) {
            display as text "Insufficient observations in year `y'"
        }
        else {
            display as error "Unexpected regression error in year `y'"
            exit c(rc)
        }
    }
    Now, this code does not actually run to completion in your example data. That's because in year 2002, we have D = 0 for all observations. That means that the D variable and all its interactions drop from the regression due to colinearity. So when the code tries to store the delta values for year 2002, it feels because the corresponding coefficients do not exist. Presumably you do not have D = 0 in all observations in year 2002 in your real data, so you won't run into that problem.

    Comment


    • #17
      Thank you so much it now works. I just have another question
      capture noisily reg E (i.D##c.R)##c.(SIZE LEV MTB) the original regression is regressing Earnings (E) on Returns (R) and D(-ve returns) and their multiplication(inetraction). I am just trying to understand the code so I got that (i) is for the indicator variable and (c) is for the categorical variable. But I do not know the ## does this represent the interaction?

      Comment


      • #18
        The i. designates a discrete variable, c. designates a continuous variable. var1##var2 denotes var1, var2, and their interaction. The interaction of var1 and var2 by itself would be denoted var1#var2. You will see this last kind of notation in the output tables. But when writing commands for models with interactions it is best to use the ## instead so that you don't accidently forget to include the constituents.

        See -help fvvarlist- for a full explanation of Stata's factor-variable notation.

        Comment


        • #19
          Thank you so much for your help really appreciated.

          Comment


          • #20
            Hi Clyde,

            I have been trying to use the code you provided and it worked however it seems to me that there is something wrong in the analysis the numbers seem to be totally inconsistent with the prior literature. I think I did something wrong in the command could you please advise? for instance what are these lines? also what is `y'? I think I did not accurately reflect the equations on STATA
            } else if inlist(c(rc), 2000, 2001) { display as text "Insufficient observations in year `y'" } else { display as error "Unexpected regression error in year `y'" exit c(rc)

            Comment

            Working...
            X