Announcement

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

  • restore command not working

    Hi, although I issue the "preserve" command, when I issue the "restore" command afterward, I get the following error:

    Code:
     restore
    nothing to restore
    r(622);
    Where am I going wrong here?
    Last edited by Taz Raihan; 05 Apr 2018, 02:11.

  • #2
    You have to first preserve to be able to restore.

    Comment


    • #3
      Abdul Adam Thanks for your response. As I mentioned in my first post, I did first preserve.

      Comment


      • #4
        @Taz Raihan can you please show the whole code?

        Comment


        • #5
          In the same session? What did you do in between preserve and restore?

          Comment


          • #6
            Here is what I have done between preserve and restore:

            Code:
                  preserve  
                  
                  by country (year): gen laggrowth= rgdpgrowth[_n-1] /*generating lagged growth rates*/
                  by country (year): gen laglrgdp= lrgdpch[_n-1]     /*generating lagged real gdp*/
                  drop if laggrowth==.
                  
                  xi: xtabond2 rgdpgrowth sxp openSachs ki politys lkg popgrowth laglrgdp i.year , ///
                  gmm(laglrgdp, collapse) ivstyle(sxp openSachs ki politys lkg i.year, equation(diff)) ///
                  ivstyle(sxp openSachs ki politys lkg i.year, equation(level)) ///
                  twostep robust orthogonal 
                  
                  est store reg1
                  
                  xi: xtabond2 rgdpgrowth sxp openSachs ki politys lkg popgrowth laglrgdp laggrowth i.year , ///
                  gmm(laglrgdp laggrowth, collapse) ivstyle(sxp openSachs ki politys lkg i.year, equation(diff)) ///
                  ivstyle(sxp openSachs ki politys lkg i.year, equation(level)) ///
                  twostep robust orthogonal 
                  
                  est store reg2
                  
                  outreg2 [reg1 reg2] using SystemGMM, excel tex(landscape) label replace
                  
                  restore

            Comment


            • #7
              You're mentioning there various user-written commands I don't use. But a glance at the code of outreg2 (SSC) shows that it also uses preserve. So, that may be messing things up. You could also try looking at the code of xtabond2.

              Comment


              • #8
                I agree with @Nick Cox.

                Comment


                • #9
                  Nick Cox Thank you, sir. Following your suggestion, I looked at the code (using viewsource) of xtabond2. It also seems to be using preserve. I guess there is not much I can do here,

                  Comment


                  • #10
                    I do not think that any of the commands using preserve could mess things up. Indeed if it were so, then many native Stata command would mess things up all the time. My guess is that Nick's question in #5 is right on spot (as usual). Taz did not run the complete code at once but interrupted the do-file somewhere between preserve and restore.

                    Taz, run the complete code in #6 and show us the output.

                    Best
                    Daniel

                    Comment


                    • #11
                      daniel klein Thanks for chiming in. The outputs are pretty long. Therefore, before I post them here, let me seek some further clarifications. When you say "run the complete code at once", do you mean that I should NOT run the codes separately line by line? Because that's what I have been doing. I have one more confusion. When I run the following codes, the variables that I am generating do not show up in the Variables window:

                      Code:
                         
                      . do "C:\Users\Anup\AppData\Local\Temp\STD01000000.tmp"
                      
                      . use "C:\Users\Anup\Google Drive\third paper\Data\Code & Results\Analysis- Started March 28 2018\data_final.dta", clear
                      
                      . 
                      end of do-file
                      
                      . do "C:\Users\Anup\AppData\Local\Temp\STD01000000.tmp"
                      
                      . xtset country year 
                             panel variable:  country (strongly balanced)
                              time variable:  year, 1975 to 1995, but with gaps
                                      delta:  1 unit
                      
                      . 
                      end of do-file
                      
                      . do "C:\Users\Anup\AppData\Local\Temp\STD01000000.tmp"
                      
                      .       preserve  
                      
                      .           by country (year): gen laggrowth= rgdpgrowth[_n-1] /*generating lagged growth rates*/
                      (104 missing values generated)
                      
                      .           by country (year): gen laglrgdp= lrgdpch[_n-1]     /*generating lagged real gdp*/
                      (104 missing values generated)
                      
                      .           drop if laggrowth==.
                      (104 observations deleted)
                      
                      .

                      Comment


                      • #12
                        If #6 is the complete evidence, I have still only a guess that commands that themselves use preserve are messing things up. Otherwise I agree with daniel klein that (a) this shouldn't happen and (b) if other things are relevant then the explanation may lie elsewhere.

                        Comment


                        • #13
                          Originally posted by Taz Raihan View Post
                          When you say "run the complete code at once", do you mean that I should NOT run the codes separately line by line? Because that's what I have been doing.
                          Yes, this is what I meant and it is what Nick meant when he was talking about "one session". Running the code line-by-line will not work the way you intend.The data is automatically restored once the do-file (more precisely: the executed parts) ends.

                          That said, I do fail to see why you want to use xi, which I suppose is the reason you need to preserve; xtabond2 supports factor variable notation, which should be used.

                          I have one more confusion. When I run the following codes, the variables that I am generating do not show up in the Variables window:
                          You do not show the complete output. I suspect there is another "end of do-file" missing. As explained above, once the do-file finishes, the original data is restored as requested. The original data did not contain the newly created variables, hence they do (no longer) show up in the variable window.

                          Best
                          Daniel

                          Comment


                          • #14
                            daniel klein Thank you for the useful information. Just to confirm that I have understood you properly: whenever I run codes from a do-file, the data automatically goes back to its original form as soon as the codes finish running. Is this what you meant?

                            I used xi because Roodman, D. 2009. How to Do xtabond2: An Introduction to "Difference" and "System" GMM in Stata. The Stata Journal, 9(1): 86-136 used it while using year dummies.
                            Last edited by Taz Raihan; 05 Apr 2018, 03:54.

                            Comment


                            • #15
                              Originally posted by Taz Raihan View Post
                              Just to confirm that I have understood you properly: whenever I run codes from a do-file, the data automatically goes back to its original form as soon as the codes finish running. Is this what you meant?
                              No. If you issue a preserve then the data is automatically restored to the current state, once the session, which might be (parts of) a do-file, ends. If you do not specify preserve, then nothing is restored later on. If you are still having trouble understanding what is going on, I suggest you just read the help file and pdf documentation on preserve; these issues are all explained there.

                              I used xi because Roodman (2009) i.e. "How to do xtabond2" used it while using year dummies.
                              Let me quickly remind you that you are supposed to give full references for literature you cite here. In this case

                              Roodman, D. 2009. How to Do xtabond2: An Introduction to "Difference" and "System" GMM in Stata. The Stata Journal, 9(1): 86-136.

                              I am guessing that David Roodman added factor variable support after he wrote the article. The support is, however, documented in the current help file of xtabond2, which I have just downloaded from SSC.

                              Edit:

                              OK, the help and manual entries for preserve focus on programming, where this command is most commonly used. Just substitute "(part of a) do-file" or more general: "session" for "program" while you read along.


                              Best
                              Daniel
                              Last edited by daniel klein; 05 Apr 2018, 03:54.

                              Comment

                              Working...
                              X