Announcement

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

  • #16
    .
    Last edited by Dr. Iqra Yaseen; 08 Jun 2023, 23:11.

    Comment


    • #17
      Clyde Schechter using the #12 code what i get is year 1995 and years 2020 to 2046....but my data set ranges from 1995 to 2019 and i just need to add more 4 years of 2020, 2021, 2022 and 2023 to the dataset with duplicate values of 1995......please help
      Last edited by Dr. Iqra Yaseen; 08 Jun 2023, 23:12.

      Comment


      • #18
        Clyde Schechter #12 code adds years 2020 to 2046 and keeps the original 1995 year, but my dataset ranges from 1995-2019 and i want to add years 2020, 2021, 2022 ad 2023 with duplicate values of year 1995. please help

        Comment


        • #19
          The code in #12, with the correction of iso_d iso_d to iso_o iso_d works correctly with the example data you originally provided. I do not see why it would not work more generally, provided that the combination of iso_o, iso_d, and year uniquely identify observations in the data set (which is verified in the first command.) Please post back with a data example where the code produces the unwanted results you speak of, and I will try to troubleshoot it.

          Comment


          • #20
            Clyde Schechter this is what i get after code #12
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input int year str40 iso3_o str19 iso3_d double tradeflow_imf_d
            1995 "ARE" "ARG"                  .
            2020 "ARE" "ARG"                  .
            2021 "ARE" "ARG"                  .
            2022 "ARE" "ARG"                  .
            2023 "ARE" "ARG"  338.6659851074219
            2024 "ARE" "ARG"                  .
            2025 "ARE" "ARG"                  .
            2026 "ARE" "ARG"    1594.0009765625
            2027 "ARE" "ARG"      2909.00390625
            2028 "ARE" "ARG"    32352.396484375
            2029 "ARE" "ARG"  2485.860107421875
            2030 "ARE" "ARG"    2385.7080078125
            2031 "ARE" "ARG"   14217.6962890625
            2032 "ARE" "ARG"   16160.2919921875
            2033 "ARE" "ARG"  520.6320190429688
            2034 "ARE" "ARG"         18021.3125
            2035 "ARE" "ARG"    5007.2041015625
            2036 "ARE" "ARG"   2818.52392578125
            2037 "ARE" "ARG"      26824.6328125
            2038 "ARE" "ARG"     54085.22265625
            2039 "ARE" "ARG"     33019.37890625
            2040 "ARE" "ARG"     49520.51953125
            2041 "ARE" "ARG"    32238.396484375
            2042 "ARE" "ARG"      40069.9453125
            2043 "ARE" "ARG"              70894
            2044 "ARE" "ARG"              48704
            2045 "ARE" "ARG"             137890
            2046 "ARE" "ARG"             186096
            1995 "ARE" "ATG"                  .
            2020 "ARE" "ATG"                  .
            2021 "ARE" "ATG"                  .
            2022 "ARE" "ATG"                  .
            2023 "ARE" "ATG"                  .
            2024 "ARE" "ATG"                  .
            2025 "ARE" "ATG"                  .
            2026 "ARE" "ATG"                  .
            2027 "ARE" "ATG"                  .
            2028 "ARE" "ATG"                  .
            2029 "ARE" "ATG"                  .
            2030 "ARE" "ATG"                  .
            2031 "ARE" "ATG"                  .
            2032 "ARE" "ATG"                  .
            2033 "ARE" "ATG"                  .
            2034 "ARE" "ATG"  .8339999914169312
            2035 "ARE" "ATG"  66.65299987792969
            2036 "ARE" "ATG"   57.8390007019043
            2037 "ARE" "ATG" 15.515999794006348
            2038 "ARE" "ATG"  47.49399948120117
            2039 "ARE" "ATG" 114.18399810791016
            2040 "ARE" "ATG"  28.04599952697754
            2041 "ARE" "ATG"  79.77200317382813
            2042 "ARE" "ATG"  691.7440185546875
            2043 "ARE" "ATG"   487.072998046875
            2044 "ARE" "ATG"   3232.97705078125
            2045 "ARE" "ATG"  564.8040161132813
            2046 "ARE" "ATG"   632.781982421875
            1995 "ARE" "BHR"      97787.3828125
            2020 "ARE" "BHR"      97787.3828125
            2021 "ARE" "BHR"      97787.3828125
            2022 "ARE" "BHR"      97787.3828125
            2023 "ARE" "BHR"      93825.2734375
            2024 "ARE" "BHR"      104146.046875
            2025 "ARE" "BHR"       94635.140625
            2026 "ARE" "BHR"         93878.0625
            2027 "ARE" "BHR"     114530.7578125
            2028 "ARE" "BHR"       108834.78125
            2029 "ARE" "BHR"         139448.625
            2030 "ARE" "BHR"      169057.296875
            2031 "ARE" "BHR"        188481.0625
            2032 "ARE" "BHR"      232619.046875
            2033 "ARE" "BHR"       221041.53125
            2034 "ARE" "BHR"          327693.75
            2035 "ARE" "BHR"        499485.1875
            2036 "ARE" "BHR"        366853.5625
            2037 "ARE" "BHR"       374665.28125
            2038 "ARE" "BHR"        577138.5625
            2039 "ARE" "BHR"         921739.125
            2040 "ARE" "BHR"         1051032.25
            2041 "ARE" "BHR"        1071890.875
            2042 "ARE" "BHR"        1135789.125
            2043 "ARE" "BHR"         1051271.75
            2044 "ARE" "BHR"         1368644.25
            2045 "ARE" "BHR"        1308318.875
            2046 "ARE" "BHR"          918474.25
            1995 "ARE" "BRA"            30552.5
            2020 "ARE" "BRA"            30552.5
            2021 "ARE" "BRA"            30552.5
            2022 "ARE" "BRA"            30552.5
            2023 "ARE" "BRA"      43889.1796875
            2024 "ARE" "BRA"              19217
            2025 "ARE" "BRA"     34471.80078125
            2026 "ARE" "BRA"    17474.599609375
            2027 "ARE" "BRA"         67546.1875
            2028 "ARE" "BRA"     110022.1015625
            2029 "ARE" "BRA"      96921.7109375
            2030 "ARE" "BRA"     19911.62890625
            2031 "ARE" "BRA"      68142.5390625
            2032 "ARE" "BRA"      81551.6328125
            2033 "ARE" "BRA"        368040.0625
            2034 "ARE" "BRA"        339175.1875
            end
            i loose years from 1996 to 2019 and get years from 2020 to 2046....but this isn"t my requirement.

            Comment


            • #21
              Yes, I see the problem now. The code in #12 worked with the original example because that example contained only year 1995. But when there are more years, things go awry. The correction, fortunately, is simple:
              Code:
              isid iso3_o iso3_d year, sort
              expand 4 if year == 1995
              by iso3_o iso3_d (year), sort: replace year = 2018 + _n if _n >= 2 & year == 1995
              isid iso3_o iso3_d year, sort

              Comment


              • #22
                thank you so much Clyde Schechter . code #21 worked.

                Comment

                Working...
                X