Announcement

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

  • Generating Fitted Values with Dummy Variables and Interaction Terms

    Hi all,

    I want to generate the fitted values for the following regression (mstat, state and year are factor variables):

    reg pollution income fam_size ib0.mstat i.state##i.year
    I want to generate the predicted values based on variable income2 instead of income, but using the coefficients from the above regression:

    gen pollution_hat= _b[_cons]+ _b[income]*income2+ _b[fam_size]*fam_size
    How should I add the dummy variable coefficients and also the interaction coefficients at the end of the above command? Is there a way other than generating all the dummy variables separately?

    Thanks,
    Last edited by Hossein Hosseini; 10 Apr 2017, 09:41.

  • #2
    I don't have time to test this approach right now, but I think it should work.
    1. Make a copy of the current dataset.
    2. In the copy, delete variables pollution and income, then rename income2 to income.
    3. Append the copy to the original dataset.
    4. Estimate your model as before.
    5. Then use predict pollution_hat to save the fitted values--this should save fitted values for all cases that have complete data for the explanatory variables.
    HTH.
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment


    • #3
      I don't think this is quite what was asked for. By re-estimating the model in step 4, a new set of coefficients will be created by regressing on income2 (now renamed income). I think what is needed is just:

      1. -drop income- and -rename income2-
      2. -predicted fitted_with_income2

      If it is necessary to keep the original income variable in the data set, instead of -drop-ping it, just -rename- it to something else. Then when you are done, restore the original variable names with more -rename- commands.

      Comment


      • #4
        Thanks, Bruce and Clyde! I did both of these. The result is the same. Just in Bruce's advice, in step 4, I estimated the model based on observations of the original file to get the initial desired coefficients:

        reg pollution income fam_size ib0.mstat i.state##i.year if _n< 147511
        Clyde's solution is easier though.

        Thanks,
        Hossein

        Comment


        • #5
          Thanks for the feedback, Hossein. I'm a relative newbie when it comes to Stata, and have a long way to go to reach Clyde's level of expertise & proficiency. ;-)

          Re my step 4, if the dependent variable (pollution) is missing in all the observations that were appended (because it was deleted in step 2), then only the original dataset would be used in estimating the model.
          --
          Bruce Weaver
          Email: [email protected]
          Version: Stata/MP 19.5 (Windows)

          Comment

          Working...
          X