Announcement

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

  • too many variables specified?

    Hi folks,

    I am using the following code to set up a panel data:

    xtset orde carrier year quarter

    I encoded both orde and carrier variables, and orde is an id for the route, carrier is the airline company. But the stata keeps showing "too many variables specified", I do not know why, hope you guys help me with this, I appreciate that very much!

    I also changed the code to the following:

    xtset orde carrier time

    The time is a dummy with value 0 before merger and with value 1 after merger, but the stata is still showing "too many variables specified". I will appreciate any help with this, thanks in advance!


  • #2
    -xtset- only allows one panel variable and, optionally, one time variable. Your initial attempt involved two of each, and your second attempt has two panel variables and one time variable. Without knowing the exact structure of your data, I can't be sure what you should do, but I think you want to create a new variable that combines orde and carrier for your panel variable. So
    Code:
    egen panel_var = group(orde carrier)

    From what you described, my guess is that what you actually want to do about time is have a quarterly date variable (whether you include it in -xtset- or not) out of your year and quarter variables. The simplest approach is to use Nick Cox's -numdate- command. You can get that by running -ssc install numdate-. Then it's:
    Code:
    numdate quarterly qdate = year quarter, pattern(YQ)
    The next question is what to do about time. If you are going to use lead, lag, and difference operators, or autoregressive models, or use -rolling-, then you need to include a time variable in your -xtset-. If you're not going to do any of those, the panel variable is all you need and you can just specify -xtset panel_var-.

    Then, if you need a time variable in your -xtset-, you can do -xtset panel_var qdate-. Otherwise, just -xtset panel_var- will suffice.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      -xtset- only allows one panel variable and, optionally, one time variable. Your initial attempt involved two of each, and your second attempt has two panel variables and one time variable. Without knowing the exact structure of your data, I can't be sure what you should do, but I think you want to create a new variable that combines orde and carrier for your panel variable. So
      Code:
      egen panel_var = group(orde carrier)

      From what you described, my guess is that what you actually want to do about time is have a quarterly date variable (whether you include it in -xtset- or not) out of your year and quarter variables. The simplest approach is to use Nick Cox's -numdate- command. You can get that by running -ssc install numdate-. Then it's:
      Code:
      numdate quarterly qdate = year quarter, pattern(YQ)
      The next question is what to do about time. If you are going to use lead, lag, and difference operators, or autoregressive models, or use -rolling-, then you need to include a time variable in your -xtset-. If you're not going to do any of those, the panel variable is all you need and you can just specify -xtset panel_var-.

      Then, if you need a time variable in your -xtset-, you can do -xtset panel_var qdate-. Otherwise, just -xtset panel_var- will suffice.
      Thank you so much, Clyde!

      Comment


      • #4
        Hi Clyde,
        Thank you so much for your help. Since I want to study the effect of a merger, I have four quarters of data before merger and four quarters after merger, each quarter I have the observations for the same "orde" and "carrier", so these 8 quarters consist of the panel data. And, I have the time (a dummy with 0 and 1) variable, and year and quarter variables. I wonder in my case how should I use the xtset command. Thank you again!

        Comment


        • #5
          Well, it looks to me like you will need to do -xtset panel_var- where panel_var is calculated as I suggested in #2.

          Optionally you could -xtset panel_var qdate-: this would enable you to run analyses that use lags and leads, or to model autoregressive error structures. Whether those kinds of analysis would be useful for you, I have no idea: this is not my field and I don't know what the substantive scienctific issues that influence those decisions are.

          There is another issue, again substantive rather than statistical, to consider here. If you need to actually estimate the variation in outcome separately attributable to carrier and to orde in order to achieve your research goals, then using a combined panel_var along the lines I have laid out will not support that. In that case, you probably need to forget about the -xt- commands and move to a multi-level model where carrier and orde are crossed random effects, or a multiple membership model. (I suppose it is possible that in your data set routes might be nested in carriers or vice versa, but as a lay person I know enough about transportation systems in the real world to know that that isn't the case generally.)

          So the final answer to your question is contingent on your obtaining clarity on your research goals and the structure of your data.

          Comment


          • #6
            Hi Clyde,
            Two questions: 1, if I use the -xtset panel_var qdate-, and then do the fixed effects regression, this means I put the fixed effect on the orde, carrier, year and quarter, right?
            2, You talked about a multi-level model where carrier and orde are crossed random effects, or a multiple membership model, could you please explain this? Don't know what the multi-level model or multiple membership model. Thank you, Clyde!

            Comment


            • #7
              1, if I use the -xtset panel_var qdate-, and then do the fixed effects regression, this means I put the fixed effect on the orde, carrier, year and quarter, right?
              No. This will set up fixed effects on the combination of orde and carrier. To get fixed effects on time, you need to specify those in the list of variables in -xtreg-. i.qdate would do that. Note, by the way, that this is fixed effects on the quarterly date. If you think there are periodic seasonal effects at the quarter level, then you would not use qdate for this but would use i.year and i.quarter separately. Do read the [XT] user's manual sections on -xtreg- before proceeding with anything!

              You talked about a multi-level model where carrier and orde are crossed random effects, or a multiple membership model, could you please explain this? Don't know what the multi-level model or multiple membership model.
              This is beyond what I could do in a forum post. If you don't know what these are, it will take you a fair amount of time to learn them well enough to use them. I would recommend the online course offered by Bristol University. It is free of charge, you can largely tailor the pace and content of the course to your level of preparedness, and Stata (though not the most recent version) is used n the course.

              Comment


              • #8
                Thank you so much, Clyde!!!
                Really appreciate your help!

                Comment


                • #9
                  Bruce:
                  Clyde mentioned an excellent online course (some years ago I downloaded the hand-outs for personal research purposes).
                  Video tutorials are very interesting and you get aware very soon about the complexity of the matter..
                  I still remember one of the first video tutorial which developed an example of pupils nested in classrooms who, in turn, were nested in schools.
                  That said, Stata bookstore reports an excellent 2-volume textbook on this topic: http://www.stata.com/bookstore/multi...ata/index.html.
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Thank you so much, Carlo!!!

                    Comment

                    Working...
                    X