Announcement

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

  • Extract and plot set of group specific coefficients

    Dear listers,

    for 200 firms I observe how their pricing responds to changes in costs in 5 periods each.
    Now I would like to obtain firm-specific estimates of cost-price-responses and plot their distribution.

    Since running a separate estimation for each firm would in expectation take rather long, I've started with this:
    Code:
    reghdfe price c.cost##firmid, absorb(year)
    Now I would like to generate a variable that contains for each firm the main effect of cost plus the relevant interaction, a bit like this:

    Code:
    gen firmresponse=.
    forval n=1/200 {
          replace firmresponse = _b[cost] + _b[cost##firmid_`n'] if firmid==`n'
          }
    One problem is that I do not know what exactly to put in between the second _b[...].
    The other is that coefficients on some of the firms get dropped due to collinearity, so I would need to make this loop run over all values including those for which no interaction was estimated, and just fill in a zero interactions for missing interactions.

    Can someone see either how I can get this code to do what I want,
    or see another, smarter way of doing it?

    Thanks so much!
    PM

  • #2
    This expansion

    c.cost##firmid
    results in

    Code:
    c.cost i.firmid c.cost#i.firmid
    See

    Code:
    help fvvarlist
    In any case, the -coeflegend- option will show you how the coefficients are named.

    Code:
    reghdfe price c.cost##firmid, absorb(year) coeflegend
    Having said that, I do not follow what you are doing. You seem to want to compute predictions, in which case see the command's documentation. reghdfe is from https://raw.githubusercontent.com/se...fe/master/src/, as you are asked to explain (FAQ Advice #12).

    Last edited by Andrew Musau; 17 Aug 2023, 05:58.

    Comment


    • #3
      Hi Andrew,

      thank you so much!
      I was not aware of the -coeflegend- option, but that's very helpful to see exactly how each estimate stored in the matrix is called and can be called upon.

      Yes, I guess I want a prediction that for each form equals the main effect _b[cost] plus that firm's interaction, e.g. for firm 5 I want _b[cost]+_b[5.firmid#c.cost].

      The remaining problem is that, although firmid contains consecutively each value between 1 and 200, -reghdfe- from SSC seems to drop about 15 interaction coefficients due to collinearity.
      But when I then loop over the 200 firms I get an error.
      I cannot solve this by saying "if ... not missing" because the problem is not that the value is missing but the estimate is.
      Can I either run this loop and ignore cases where _b[`n'.firmid#c.cost] does has not been estimated, or generate missing estimates in the case of collinearity, or somehow pick up after the regression which coefficients were not estimated and somehow use that information when coding my loop?

      Comment


      • #4
        Code:
        help capture

        Comment


        • #5
          Thanks!
          Not as good for the distribution as being able to use just the main effect plus 0 where interactions are collinear, but at least it runs through for starters.

          Comment


          • #6
            If a variable is omitted, its coefficient is equal to 0. Can you present a data example where you are encountering problems?

            Comment

            Working...
            X