Announcement

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

  • xtpoisson prediction

    Hi,

    I am using xtpoisson fixed effect regression. After getting the coefficients as follows, I want to make the prediction and get the accuracy of the model. I see simple predict gave me numbers in specific range for event count.

    Any help please?

    Code:
    . xtpoisson count average_temprature average_precipitation humidity  avg_shifted commulitave_2_years, fe irr
    note: 1038 groups (21798 obs) dropped because of all zero outcomes
    note: humidity dropped because it is constant within group
    
    Iteration 0:   log likelihood = -35735.979  
    Iteration 1:   log likelihood = -35032.504  
    Iteration 2:   log likelihood = -35032.009  
    Iteration 3:   log likelihood = -35032.009  
    
    Conditional fixed-effects Poisson regression        Number of obs    =  41,643
    Group variable: fips                                Number of groups =   1,983
    
                                                        Obs per group:
                                                                     min =      21
                                                                     avg =    21.0
                                                                     max =      21
    
                                                        Wald chi2(4)     = 1394.43
    Log likelihood = -35032.009                         Prob > chi2      =  0.0000
    
    ---------------------------------------------------------------------------------------
                    count |        IRR   Std. err.      z    P>|z|     [95% conf. interval]
    ----------------------+----------------------------------------------------------------
       average_temprature |   1.208188   .0065024    35.14   0.000      1.19551    1.220999
    average_precipitation |   .9954726   .0108513    -0.42   0.677     .9744301     1.01697
              avg_shifted |   1.005804   .0009224     6.31   0.000     1.003998    1.007613
      commulitave_2_years |   1.000069   .0001511     0.46   0.646     .9997733    1.000366
    ---------------------------------------------------------------------------------------
    Last edited by amera amery; 15 Apr 2022, 14:18.

  • #2
    What do we mean "get the accuracy of the model"?

    You also say
    I see simple predict gave me numbers in specific range for event count.
    implying that you've used the predict post-estimation command. I don't understand what the issue is here.

    Comment


    • #3
      I meant getting predicted values (y hate) and comparing it with real values (Y) to check the accuracy. how to get y hate values?

      Comment


      • #4
        see
        Code:
        help xtpoisson postestimation##predict

        Comment


        • #5
          I found this code in one post and it gives accurate results. But why do we have to go through this to get y hat for Poisson regression ? Any references?

          Code:
           
           sysuse auto, clear g id=rep78 drop if id==. xtset id xtpoisson price mpg, fe predict double fitted, xb gen double yhat=exp(fitted)  egen meany=mean(price) , by(id)  egen meanyhat=mean(yhat), by(id)  gen double exp_alpha=meany/meanyhat if meanyhat>0  replace yhat=yhat*exp_alpha if meanyhat>0 su price yhat

          Comment


          • #6
            I still don't understand.

            I'm not at my computer, but if we did
            Code:
            xtpoisson y x
            
            predict yhat
            we get our predictions from the model, no additional complications needed. As Rich said, go to your stata terminal and type
            Code:
            help xtpoisson postestimation##predict

            Comment


            • #7
              Dear amera amery et al.:

              I am afraid it is not possible to obtain meaningful predictions after xtpoisson with FE; that is illustrated here.

              However, in your case you have a reasonable T and therefore so you can get predictions by adapting the code below

              Code:
              clear all
              sysuse auto
              xtset rep78
              xtpoisson price mpg , fe
              predict double xb if e(sample)==1
              g double yhat=exp(xb)
              egen meany=mean(price) if e(sample)==1, by(rep78)
              egen meanyhat=mean(yhat) , by(rep78)
              gen double exp_alpha=meany/meanyhat
              replace yhat=yhat*exp_alpha
              Best wishes,

              Joao

              Comment


              • #8
                @Joao Santos Silva Thank you very much, this code works with my model and gives very close values for the dependent variable. But what I meant is why we have to do this process, why predict command does not give the direct predicted value?

                Comment


                • #9
                  Dear amera amery

                  That is because to get the fitted values you need the fixed effects and most fixed effects estimators wipe them out rather than estimating them. A good textbook should explain that.

                  Best wishes,

                  Joao

                  Comment

                  Working...
                  X