Announcement

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

  • #16
    I thought of that but was hoping that I could do this with a single command rather than one for each year. I don't understand why you need to question why I need separate data sets for each year.

    Comment


    • #17
      I really would suggest simpler code if I knew it. Any way, what I suggest is a few lines long, there are no other solutions on offer, and you've not indicated that my code doesn't work.

      Otherwise, there is the XY problem. http://xyproblem.info/ People often ask how to do something and the real problem is that they should be asking a different question. If that doesn't arise often in your field of expertise I would be astonished, but that is where I close.

      Comment


      • #18
        I was hoping to find one command that would do this rather than having to do this for each year. I know how to do that.
        I tried:

        forvalues i=1903/2017 i: {
        2. savesome country gwno`i'-ptratio_seced_ES`i' using newwepwide`i'
        3. }

        but received
        invalid syntax
        r(198);

        And I am sorry if you think that it is an odd thing to do.

        Comment


        • #19
          I don’t know where

          Code:
          i:
          fits in your intention but from Stata’s point of view it will be the invalid syntax being reported.

          Comment


          • #20
            I was hoping to find one command that would do this rather than having to do this for each year. I know how to do that.
            I tried:

            forvalues i=1903/2017 i: {
            2. savesome country gwno`i'-ptratio_seced_ES`i' using newwepwide`i'
            3. }

            but received
            invalid syntax
            r(198);

            And I am sorry if you think that it is an odd thing to do.

            Comment


            • #21
              To further validate the xy-problem: there is no need at all to reshape wide with the suggested final data saved in individual files per year

              Starting from e.g.,:
              Code:
              * Example generated by -dataex-. To install: ssc install dataex
              clear
              input str1 country float(year gdp_WDI_PW_PW gdppc_WDI_PW_PW growth_WDI_PW_PW)
              "A" 2000  3.913819  8.597421  9.196262
              "A" 2001 1.1966132 1.3407556  6.934533
              "A" 2002  7.542434  4.884418 2.1540258
              "A" 2003  6.950233  8.712188  8.285889
              "A" 2004  6.866152  7.664683  .4421535
              "B" 2000  9.319345 2.5125554  8.630378
              "B" 2001  4.548882 1.6636478  3.526046
              "B" 2002   .674011  7.437958    7.7204
              "B" 2003  3.379889  9.805113  5.861199
              "B" 2004  9.748848  7.295772  3.227766
              "C" 2000  7.264384  9.011049 1.7293066
              "C" 2001  .4541512  2.643649  8.053644
              "C" 2002  7.459667  8.856509  3.060019
              "C" 2003  4.961259   8.82112 2.1909966
              "C" 2004  7.167162   7.48933   7.24731
              end
              All that is needed is:
              Code:
              forval y = 2000/2004{
                    preserve
                    keep if year==`y'
                    save wepwide`y'
                    restore
              }

              Comment


              • #22
                Great. many thanks!

                Comment

                Working...
                X