Announcement

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

  • Declare a data set as a Panel data, use tsset or xtset !

    Hi !
    My data is a panel data. I have id (lpermno variable) and time (mydatemonthly variable). I was trying to declare it as a panel data but was not sure if I have to use tsset or xtset command ! And if there is any difference between the two commands (some links on the web say that there is no real difference, but if that's the case why do we have two commands for the same thing!) . And does it hurt to generate variables within a file or merge data files before declaring them as panel data first !
    Thanks in advance !
    Attached Files

  • #2
    It depends on which commands you plan to use for analysis. For example, are you planning on using -xtreg-? If yes, then -xtset- the data.

    Comment


    • #3
      If you have both a panelid and a time variable, it is six of one and half a dozen of the other. The only difference is the order in which you enter the two variables. e.g.

      Code:
      xtset panelid year
      tsset year panelid
      both do the same thing. In both cases, the first parameter is required and the second is optional.

      EDIT: As noted below, I was wrong. For both xtset and tsset it should be panelid year
      Last edited by Richard Williams; 31 Jul 2014, 14:44.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Sorry Richard, but the syntax is the same in both cases (as long as you have both the panelid and time variable). The panelid comes always first, both with xtset and tsset.
        Last edited by Sebastian Kripfganz; 31 Jul 2014, 14:42.
        https://twitter.com/Kripfganz

        Comment


        • #5
          I stand corrected. The required variable differs, but if you specify both it is indeed panelvar followed by timevar for both xtset and tsset.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            Both commands are implemented as ado-files. Typing viewsource xtset.ado reveals that xtset actually calls tsset which was introduced as a kind of wrapper in Stata 9 (c.f. help whatsnew9). More experienced users might remember.

            Best
            Daniel

            Comment


            • #7
              1

              Comment


              • #8
                In Stata 7 there was no -xtset-, there was only -tsset-.

                To my knowledge the two commands -xtset- and -tsset- are equivalent.

                I am also curious as to why -xtset- was introduced.

                Comment


                • #9
                  #8

                  xtset and tsset overlap but they are not identical!

                  xtset allows a panel identifier only. tsset allows a time identifier only. Where they overlap is when two variables are supplied in which case the first is treated as a panel identifier and the second as a time variable.

                  The offlap is reason enough for different commands.

                  Comment


                  • #10
                    Nick is right that with -tsset- one cannot set only panel identifier, so I was wrong to say that they are equivalent.

                    The introduction of -xtset- might have been with the purpose of more consistent design across commands in Stata.

                    In Stata 7 the situation was somewhat asymmetric because one had to -tsset- his data to use time series commands, but one did not have to declare the data as panel when using -xt- commands.

                    In modern Stata we have to -xtset- our data to use -xt- commands.

                    What we do now with

                    Code:
                    xtset panelvar
                    
                    xtreg y x
                    in Stata 7 was done with

                    Code:
                    xtreg y x, i(panelvar)
                    and the latter syntax still works, but went undocumented.

                    Comment

                    Working...
                    X