Announcement

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

  • Transform panel data into a time series

    Dears,

    I have a panel data of countries and years. I need to make it look like a time series. I want to get a new variable id e.g. 11, 12 (first country first year, first country second year). Could you please help me get that in stata?

    Regards,

    Arshad

  • #2
    Arshad:
    If I get you query right, there's no need to create a new variable.
    Simply type:
    Code:
    sort id (year)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you Carlo for reply.
      Actually only id variable is 1.2.3.4.....
      i want something like that would indicate country as well. e.g. (id such that, id=11, 12, 13 (for US year 1, year 2, year3), id=21, 22, 23 (for canada year1, year 2, year 3)

      I hope i explained it right.

      ARSHAD

      Comment


      • #4
        Hello Arshad,

        Carlo gave insightful advice.

        Again, since you didn't give much information, it is sort of guessing, so to speak.

        Therefore, I kindly suggest to share data - full, abridged or a mock example - under CODE delimiters or by installing the SSC dataex, as recommended in the FAQ.

        That said, provided we have a time variable as well the ID variable, we are supposed to use xtset for a panel data analysis and tsset for time series analysis.

        Hope that helps.
        Best regards,

        Marcos

        Comment


        • #5
          Arshad:
          thanks for further clarifications.
          Provided that Marcos' advice still holds, I would think about something like:

          Code:
          . bysort id (year): g index=sum(1)
          
          . g new_var=egen concat( idcode index)
          
          . egen  new_var=concat( idcode index)
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Carlo Lazzaro's second line of code was I think left in by mistake and certainly it would not run. It's the first and third lines that are pertinent.

            Comment


            • #7
              Nick is right.
              Sorry for the mishap.
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                I tried something here: https://www.jamelsaadaoui.com/from-p...es-with-stata/

                Any comments or remarks are welcome.

                Kind regards,

                Jamel

                Comment

                Working...
                X