Announcement

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

  • Temporary file for merge

    Dear Statalisters,

    In a do editor if I generally write code line by line and execute a few lines in a batch, but not the entire program.

    suppose I have the following code :


    use master
    keep xvar1 yvar fyear ...

    tempfile master1
    save "`master1'"


    use havedata
    keep yvar fyear ...

    tempfile have1
    save "`have1'"

    merge 1:1 yvar fyear using "`master1'"



    in this case, i thought I am merging have1 with master1

    my question is : do I need to issue preserve restore command in between.

    It seems to me that temp files must be used in a batch, that is , I can't hight the first 4 lines, then the next 4 , then the 9th line, because when I reach merge statement, the previous temp information will be lost. Am I correct about this?


    Regards,
    Rochelle








  • #2
    If you are using the tempfile command, you must refer to the temporary product within the same "portion" of code being executed. Which in your case as I understand means every two lines.
    I see no point in executing a do file line by line. It is not designed for that. Try things interactively from command line, then put everything into a do-file and run it.

    Best, Sergiy

    PS: Please, format the code with the code tag when posting

    Comment


    • #3
      Originally posted by Rochelle Zhang View Post
      It seems to me that temp files must be used in a batch, that is , I can't hight the first 4 lines, then the next 4 , then the 9th line, because when I reach merge statement, the previous temp information will be lost. Am I correct about this?
      You are correct.

      Originally posted by Sergiy Radyakin View Post
      I see no point in executing a do file line by line. It is not designed for that.
      I see no problem with executing a few lines from a do-file at a time. The Do-File Editor has an "Excecute selection" button exactly for that purpose.

      Comment


      • #4
        Thank you Sergiy and Friedrich !

        @ Sergiy , where is the code tag formatting?

        Comment


        • #5
          Rochelle Zhang , the code formatting tag looks like the # sign in the formatting panel. Press the "underlined A" icon to show the formatting panel.
          Friedrich Huebler , executing by portions is not always possible. Rochelle's is just a case like that. Simpler example:
          Code:
          tempfile tmp
          
          save "`tmp'"
          Anything referring to locals not defined in the same portion of the code will not work as designed, since it will be executed in a new context of the temporary do file generated by the do-editor from the selected code fragment.

          Comment


          • #6
            Thank you Sergiy.

            Comment


            • #7
              Originally posted by Sergiy Radyakin View Post
              [USER="774"]Anything referring to locals not defined in the same portion of the code will not work as designed, since it will be executed in a new context of the temporary do file generated by the do-editor from the selected code fragment.
              This was already established in posts #2 and #3, I didn't say anything to the contrary. My last post referred to your statement "I see no point in executing a do file line by line". It is possible (although not always), it may be preferred by some users and the Do-File Editor was designed for this purpose.

              Comment

              Working...
              X