Announcement

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

  • Estimated fitted value with mean of coefficient from regression.

    Dear all,

    My data includes 300 firms from 2000 to 2017. I estimate fitted values by year as follows:
    Code:
    egen group = group(year)
    gen fitted = .
    summarize group, meanonly
    
    forval g = 1/`r(max)' {
        regress y x1 x2 if group == `g'
        predict work
        replace fitted = work if group == `g'  
        drop work
    }
    My question: How can I estimate the fitted value with the mean coefficient from these regressions? I can obtain the mean coefficient with the following code:
    Code:
    statsby, by(year) saving(tempfile, replace): regress y x1 x2
    However, I don't know the command to calculate the fitted value of y with the mean coefficient?

    I would really appreciate all the help I can get.

    Best regards
    --------------------
    (Stata 15.1 MP)

  • #2
    You have 18 years of data and have run 18 regressions. In the code you show, the fitted value for each observation uses the coefficient and intercept estimates from the regression on the data for the year that observation is from.

    If I understand you correctly, you now want to calculate a new fitted value that for every observation uses the average of the 18 coefficient estimates for x1 and x2 and the average of the 18 intercept estimates, regardless of the year the observation is from.

    A few moments reflection shows that this fitted value will be the same as the average of the 18 fitted values created by separately applying the coefficient estimates from each of the 18 regressions to each observation. That is, instead of averaging coefficient estimates, average fitted values.

    Something like this would do that.
    Code:
    generate totfit = 0
    forval g = 1/`r(max)' {
        regress y x1 x2 if group == `g'
        predict work
        replace totfit = totfit+work  
        drop work
    }
    generate fitted = totfit/`r(max)'

    Comment


    • #3
      Hi William.

      You understand me correctly and your reply is quick and perfect. Thanks so much!
      --------------------
      (Stata 15.1 MP)

      Comment


      • #4
        Hi William Lisowski and everyone,

        Continue with the above example (300 firms from 2000 to 2017). Now, I add more information: 300 firms belong to 3 different industries (e.g., energy, chemicals, medical).

        I want to group these firms according to the three industries and perform annual, cross-sectional regressions for each industry to calculate fitted values and average fitted values like in #1.

        How can I code this task?

        I would really appreciate all the help I can get.

        Best regards
        Last edited by Linh Nguyen; 07 Jan 2019, 07:16.
        --------------------
        (Stata 15.1 MP)

        Comment

        Working...
        X