Announcement

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

  • Sorting Years in a panel data set

    Hi everyone,

    I have a panel data set of more than 100 companies with different variables,
    such as Dir Equity, and family equity by years from 2008 to 2019 and managerial and individual ownership from 2018 to 2012 the example is given below,

    input str7 Companies int(Year Years) double(Managerialownership Individualownership Institutionalownership)

    "" . . . . .
    "AABS" 2008 2018 2845279 13072218 863344
    "AABS" 2009 2017 2354497 1286968 863344
    "AABS" 2010 2016 2553497 1526550 863344
    "AABS" 2011 2015 2553497 2112150 863344
    "AABS" 2012 2014 2353497 1728013 863344
    "AABS" 2013 2013 2301997 556517 2246527
    "AABS" 2014 2012 2550350 760982 2766391
    "AABS" 2015 2015 . . .
    "AABS" 2016 2016 . . .
    "AABS" 2017 2017 . . .
    "AABS" 2018 2018 . . .
    "AABS" 2019 2019 . . .
    "AASM" 2008 2018 7977744 2900602 1814370
    "AASM" 2009 2017 8457083 2892597 1794370
    "AASM" 2010 2016 8457083 2898103 1817370
    "AASM" 2011 2015 8457083 2633262 2082211
    "AASM" 2012 2014 8457083 2487363 2228108
    "AASM" 2013 2013 8457083 2471863 2243610
    "AASM" 2014 2012 8457083 2387463 2244101
    end
    [/CODE]
    I want to sort years in the same order either Ascending order or Descending Order
    Kindly help me in this regard


  • #2
    I think you have not copied the [CODE] part of the output generated by the dataex program. This is why the data sample is not properly formatted. The description of the problem is not clear either. I assume that you have copied and pasted two datasets that have mis-matched company-year observations. To properly match the observations in the two dataset, it will require merging the two datasets on the key variable companies and Year. Here is the strategy you may want to follow:

    1. Save both the data sets as separate files, each one having the variables companies and Year variable. (Note you have a variable Year and another Years, both the variable should be named exactly the same for merging purpose).

    2. Load the first dataset into Stata

    3. Merge the second dataset into the first one using companies and Year as merge criterion.

    Code:
    use dataset1, clear
    merge 1:1 companies Year using dataset2
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Thank You Sir for your detailed response

      Comment


      • #4
        Originally posted by Attaullah Shah View Post
        I think you have not copied the [CODE] part of the output generated by the dataex program. This is why the data sample is not properly formatted. The description of the problem is not clear either. I assume that you have copied and pasted two datasets that have mis-matched company-year observations. To properly match the observations in the two dataset, it will require merging the two datasets on the key variable companies and Year. Here is the strategy you may want to follow:

        1. Save both the data sets as separate files, each one having the variables companies and Year variable. (Note you have a variable Year and another Years, both the variable should be named exactly the same for merging purpose).

        2. Load the first dataset into Stata

        3. Merge the second dataset into the first one using companies and Year as merge criterion.

        Code:
        use dataset1, clear
        merge 1:1 companies Year using dataset2
        Sir while merging the two data-sets I got the following message from the Stata

        merge 1:1 Companies Year using "C:\Users\DELL\Desktop\Thesis Data\Preparing final data set\dataset2.dta"
        variables Companies Year do not uniquely identify observations in the master data
        r(459);

        Comment


        • #5
          Code:
          duplicates report Companies Year 
          duplicates list Companies Year

          https://www.stata.com/support/faqs/d...d-time-values/

          Comment


          • #6
            This means that there are duplicate values in your dataset2. Open that dataset and try to use the commands suggested by Nick Cox. This will help you to identify the duplicate observations. check them carefully, if they are duplicates, you can then delete them with
            Code:
            duplicates drop Companies Year, force
            Then save the dataset2, and try the merge command again.
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment


            • #7
              One way you can get duplicates is through repeated missing values on one or both variables.

              Comment


              • #8
                Originally posted by Attaullah Shah View Post
                This means that there are duplicate values in your dataset2. Open that dataset and try to use the commands suggested by Nick Cox. This will help you to identify the duplicate observations. check them carefully, if they are duplicates, you can then delete them with
                Code:
                duplicates drop Companies Year, force
                Then save the dataset2, and try the merge command again.
                Thank You Sir now it is merged after applying your command. God Bless You!

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  Code:
                  duplicates report Companies Year
                  duplicates list Companies Year

                  https://www.stata.com/support/faqs/d...d-time-values/
                  Thank You Sir, it is done now, Good Bless You!

                  Comment

                  Working...
                  X