Announcement

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

  • discard

    Is it possible to use discard from within a program?

  • #2
    Interesting question. I haven't tried it. Sounds like a bad idea.

    Comment


    • #3
      Nick Cox When collaborating, someone may change the program without warning. So when i run the program i would like it to reload itself before it does anything. Do you think this is possible?

      Comment


      • #4
        I am quite possibly not getting this. But If your collaborators do that, you need different rules of collaboration, or different collaborators. Seriously.

        It's a strong personal rule never to write a program with someone else without mutual trust and some protocol for flagging to each other what you have done. The optimum number of collaborators is 1. (But many people work in different ways.)

        Also, and again seriously, how can anything you write protect your program against changes by someone else? I suppose what you could do is (e.g.) put your program on ssc and then download it in the code you give. But then your collaborator is likely to get confused.

        Comment


        • #5
          Nick Cox Thank you for the advice. In your opinion, is there a way to reload a program on the fly? Regrettably, discard does not seem to work.

          Comment


          • #6
            I am getting more puzzled here. This isn't a matter on which opinions are any use. I do use discard interactively. I haven't tried putting discard in the middle of a program; that seems an odd thing to want to do. You'd need to experiment to see what happens.

            Comment


            • #7
              I already have and it does not work. I was wondering if anyone here had any other ideas.

              Comment


              • #8
                We've moved in 11 minutes from "does not seem to work" to "does not work". I am not surprised either way. Other ideas I think would be more likely with precise code examples and more detail on what you want.

                Comment


                • #9
                  I am not sure whether i can be more clear on this. I want to reload an ado file containing a program. Because the program in the ado file may change, i would like the ado file with the program to be reloaded into memory every time i run the program. For example:

                  Code:
                  program foo
                  
                  discard
                  foo
                  .
                  .
                  .
                  end
                  Unfortunately, discard does not work. The program does not reload before it continues. I was wondering if i can force Stata to reload the program from the ado file while the same program is still running.

                  Comment


                  • #10
                    Is there a reason using:

                    Code:
                    cap prog drop programname
                    before the program definition won't work for you?

                    Comment


                    • #11
                      Honestly, I never did get the idea of putting

                      Code:
                      capture program drop
                      before the program statement. Say we have foo.ado defining the program foo like

                      Code:
                      capture program drop foo
                      program foo
                      ...
                      end
                      Now assume there is another program foo already loaded in memory. Stata will always execute this latter program and not even look for foo.ado. Only if there is currently no program foo in memory will the ado file be executed. But then there is no need to drop a non-existing program, of course.

                      It seems the same reasoning applies to Belinda's problem. The discard statement, even if it did work, would never be executed, once another program foo is loaded in memory. Maybe a worked example of what "did not work" means here would help along with an explanation of what the expected outcome would have been.

                      I might not get the full picture here, though.


                      Best
                      Daniel
                      Last edited by daniel klein; 12 Jun 2017, 23:31.

                      Comment


                      • #12
                        A good reason for program drop foo is that you are editing a program progressively, removing a bug or adding a feature at each iteration. (Or, as often in my experience, failing to do either.) So, you're saying, No, use this version of the program, not the one you have in memory. Once the program is stable it loses that rationale.

                        Comment


                        • #13
                          I have been using program drop and still use it a lot, precisely when I am changing things and re-run the code as if it was a regular do-file (another place where you can have programs and where dropping them before definition is a valid option) to define the program over and over, manually. However, in an ado-file that is treated as such, i.e. not run manually but automatically, it just does not make any sense to put this statement as the first line.

                          I still do not fully understand Belinda's situation.

                          Best
                          Daniel
                          Last edited by daniel klein; 13 Jun 2017, 02:56.

                          Comment


                          • #14
                            I have been using program drop and still use it a lot, precisely when I am changing things and re-run the code as if it was a regular do-file (another place where you can have programs and where dropping them before definition is a valid option) to define the program over and over, manually.
                            The idea is to make this process happen automatically. I would be happy to settle for something less, for example when i run foo, the program to reload the foo.ado and exit. But i am not sure if even this is possible?
                            Last edited by Belinda Foster; 13 Jun 2017, 03:24.

                            Comment


                            • #15
                              Still not clear to me at all, sorry. Would a simple wrapper do?

                              Code:
                              program foo2
                                  version 14.2
                                  
                                  capture program drop foo
                                  foo `0'
                              end
                              If not, please create a worked example illustrating the problem that you are facing.

                              Best
                              Daniel

                              Comment

                              Working...
                              X