Announcement

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

  • #31
    Thank you Joao Santos Silva! That's great to hear -- I'm a big fan of sticking to the most simple GOF measures.

    Jeff Wooldridge, thank you for your advice! Good to know that Pearson residuals are useful more generally. I guess I'm not totally sure I understand -- are you saying that the ratio of variance to mean needs to be the same for each observation, even if that ratio is not 1:1? That sounds very restrictive, so I'm probably misinterpreting.

    Re IPP in the context of RESET, R^2 etc -- I used xtpoisson for the RESET test as well as in calculating R2 instead of using poisson with i.id. I have 10 years of data, so I was hoping the individual effects that were differenced out were good estimates. Should this resolve the problem you're mentioning?

    Comment


    • #32
      H Joao,

      Does you command code depend on whether xtpoisson results are reported as IRR or not? It does not seem to. Am I correct?
      I am a newbie at using xtpoisson and still have alot to learn about Stata, so that might be a silly question.

      Thanks, Bryan

      Comment


      • #33
        Dear Bryan Burke,

        I am sorry but I do not know what command you are referring to.

        Best wishes,

        Joao

        Comment


        • #34
          Hi Joao,
          Thanks for those Stata commands to calculate fitted values for an in-sample prediction using xtpoisson. However, how can it be adapted for an out-of-sample prediciton? If I am making an out of sample prediction, I would not have observed values for "Price" in the fourth line.

          egen meany=mean(price), by(id)
          Last edited by Bryan Burke; 09 Dec 2020, 00:01.

          Comment


          • #35
            Hi Joao,

            I am so sorry for the formatting problems. I am new to statalist. It was these example commands of yours to calcularted fitted values for xtpoisson fixed effects. They work great for in-sample predictions, but how can they be used for out of sample predictions when the DV price is not known? I guess price is actually in line 7, not 4. How can these commands be adapted for that use, please?

            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


            Thanks,

            Bryan
            Last edited by Bryan Burke; 09 Dec 2020, 00:25.

            Comment


            • #36
              Dear Bryan Burke,

              To do that you need to replace the missing observations of the fixed effect (exp_alpha) with the estimates obtained within the sample and apply the method above. Note that, of course, this is only valid for large T.

              Best wishes,

              Joao

              Comment


              • #37
                Hi Joao,
                That (comment #36) seems consistent with Dimitriy's expanded set of options over at StackExchange. I prefered his option #2 for my needs. Thoughts?
                https://stats.stackexchange.com/ques...om-conditional

                Bryan

                Comment


                • #38
                  Originally posted by Joao Santos Silva View Post
                  Dear Bob,

                  So many people ask that question that I prepared an example illustrating how to do it. The example uses the auto dataset from Stata, but you can easily modify it to fit your case:

                  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
                  All the best,

                  Joao
                  I am wondering why am I getting exactly the same predicted values as the original values? What does this mean? The only difference is that I set both panel id and time id, and in when calculating mean by clusters, I specified by(panel_id time_id).

                  Comment


                  • #39
                    Dear Tracy Yang,

                    I think you answered your own question: do not use time_id when computing the mean by clusters.

                    Joao

                    Comment


                    • #40
                      Hi Joao, I tried different model specifications for the same dependent variable, and got yhat very close to meany for all specifications.

                      I followed your code and used by(panel_id) to calculate mean y and mean yhat.

                      Looks like the estimated values do not depend on the model specification, which is quite counter intuitive. Any thoughts why this is happening? Or maybe could you please explain a little bit how you come up with this way to get the estimated values?

                      Thanks

                      Comment


                      • #41
                        Dear Tracy Yang,

                        The estimated values depend on the model specification; if that is not what you are finding, you are doing something wrong. Please show us what you are doing so that we can check it.

                        Best wishes,

                        Joao

                        Comment


                        • #42
                          Here is the code.
                          Code:
                          xtset panel_id time_id
                          
                          xi: xtpoisson y x1 x2, fe
                          
                          predict double fitted
                          gen double yhat=exp(fitted)
                          egen meany=mean(y) , by(panel_id)
                          egen meanyhat=mean(yhat), by(panel_id)
                          gen double exp_alpha=meany/meanyhat if meanyhat>0
                          replace yhat=yhat*exp_alpha if meanyhat>0
                          Then I tried another model, where I replaced x2 with x3. Here is the code.
                          Code:
                          xi: xtpoisson y x1 x3, fe
                          
                          predict double fitted
                          gen double yhat1=exp(fitted)
                          egen meany=mean(y) , by(panel_id)
                          egen meanyhat=mean(yhat1), by(panel_id)
                          gen double exp_alpha=meany/meanyhat1 if meanyhat1>0
                          replace yhat1=yhat1*exp_alpha if meanyhat1>0
                          And yhat and yhat1 are giving exactly the same statistics summary. Not sure what is gong wrong.

                          Thanks for the help.

                          Comment


                          • #43
                            Dear Tracy Yang,

                            In the second model you are not creating meanyhat1.

                            Best wishes,

                            Joao

                            Comment


                            • #44
                              Joao Santos Silva Joao Sa

                              That is a typo, I did create meanyhat1. Otherwise, this code would throw errors, as meanyhat has already existed.

                              Thanks

                              Comment

                              Working...
                              X