Announcement

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

  • Obtaining predicted values in a FE model

    Hello everyone,

    for my masters thesis I am estimating a fe model with xtreg using data on country and year level. I used the country (30 obs) as the id variable in the panel and added year dummies (i.year from 2011 to 2019) to account for time-variant effects. For context: it estimates the influence of national-expenditures on territorial or consumption-based emissions, taken in logs.

    Code:
     xtreg logterr logne EU EUxNE loggdp logpop Openness i.year, fe vce(cluster id)
    With the estimated parameters I want to calculate the values of the emissions for the last period (2019) in the dataset using the values of national expenditures from the first period (2011), leaving every other independent variable as it was. This I want to do for every single country seperately. Is there a quick way to do this via predict commands? I read through the predict and adjust manuals in STATA and looked in the forum but couldn't figure out how to obtain the predicted values.

    Help would be much appreciated.

    Best regards,
    Niklas

  • #2
    There is no quick solution to this. You have to do it by brute force: replace the values of NE and EUxNE by their 2011 values, run -predict-, and then restore the data to its original configuration.
    Code:
    //  PRESERVE ORIGINAL VALUES OF NE AND EUxNE VARIABLES
    foreach v of varlist NE EUxNE {
        clonevar `v'_orig = `v'
    }
    
    //  CALCULATE VARIABLES CONTAINING THE 2011 VALUES OF NE AND EUxNE
    by id, sort: egen NE2011 = max(cond(year == 2011, NE, .))
    gen EUxNE2011 = EU*NE2011
    
    //  REPLACE NE AND EUxNE BY THEIR 2011 VALUES
    foreach v of varlist NE EUxNE {
        replace `v' = `v'2011
    }
    
    //  CALCULATE PREDICTED OUTCOMES
    predict wanted if year == 2019, xb // ??xbu  WHICH PREDICTED VALUE DO YOU ACTUALLY WANT
    
    
    //  RESTORE ORIGINAL VAUES OF NE AND EUxNE
    foreach v of varlist NE EUxNE {
        replace `v' = `v'_orig
    }
    
    drop *2011
    Note: As no example data was provided, this code is untested and may contain errors. The gist of it is correct, but you may need to modify it to get it to work correctly. In the future, when asking for help with code, it is best to post example data. And the helpful way to do that is with the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.


    Comment


    • #3
      Thank you very much for your reply and tips for future posts. I will keep them in mind.

      Comment

      Working...
      X