Announcement

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

  • when should I use program?

    I start to read program tutorial in Stata. But I'm still confused when I should use program.

  • #2
    You use program when you want to define a program. This seems tautological, so I am not quite sure how helpful that is.

    The problems is that I am not quite sure what the confusion is, so it is hard to give a more detailed answer. Can you tell us more about what you want to do, and why program confuses you?

    Maybe this helps? http://www.maartenbuis.nl/workshops/...l#slide31.smcl
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Let me give an example. I think -auto- is an enough example. Remember that in auto, we have foreign and domestic cars.

      I have multiple lines codes that should deal with foreign and domestic cars separately. Is this a program?

      Comment


      • #4
        Hi Yao,
        I think your question is still very vague.
        Furthermore, it also depends on what do you call a "program"
        A program is meant to do the same step of procedure every time. For your "example," you may want to
        1. load data
        2. summarize data for foreign cars
        3. summarize data for domestic cars
        4. Make a model explaining the prices of foreign and domestic cars

        You can do this using just the command window in Stata, but a more effective way would be to create a "do-file", so it always do all the steps above, whenever you need.

        You can also write small rutines using what Maarten mentioned. This are "programs" in a more proper sense of the word, but the idea is the same. Whenever the program is called, it will do all the steps you "programmed it" to do.

        So, regardless if you have 1 line of code, or 1000s, you will most likely be writing dofile programs. But for more advance programming, you will need more dedicated work.
        HTH

        Comment


        • #5
          I agree with Maarten Buis and FernandoRios

          When you need to ... is one not quite empty answer.

          Anyone who fired up Stata and did at least one thing they wanted to do by typing commands has written a successful program.

          Anyone who wrote a do-file and/or ran various commands from it that worked has written a successful program.

          Stata has a stricter sense in which a program means whatever is defined by a program command.

          There are many extremely experienced Stata users -- in some cases with experience over >20 years -- who have never written a program in this sense, because they don't need to. Or in some serious cases they don't do that any more because they now use what StataCorp has added or other community contributions.

          I started out in computing writing FORTRAN programs (now we write Fortran) because that was the only way to do the kind of things I wanted to do. I didn't write many and they weren't very good at all and their development was painfully slow, although only some of that was down to my incompetence. (The environment when I started was submitting card decks, getting lineprinter output, no interaction, no text editor that I knew of and could access, but matters improved quickly.)

          Fast forward to when I started Stata. For some while I didn't write programs at all, just do-files. The syntax for defining programs seemed complicated and scary. I just wrote do-files that took arguments. It's hard to reconstruct exactly what happened to tip me over to writing programs any strict sense, but I suppose I wanted options and the functionality of in and especially if.

          I know more about programming now, having written various, but the vast majority of my daily practice is still based on playing interactively and writing do-files. I cultivate large areas of ignorance. Programming dialogs is one. I like and use Mata a lot but am not competent in its more advanced features.

          Much depends on what else you have used. If you have a background in programming mainstream languages or in other statistical software, that can be a great help -- and a hindrance too. Stata has ways of doing things that take a lot of getting used to if you are more accustomed to other kinds of programming.

          Comment


          • #6
            I agree with all of the above, but let me give a short answer: no, you should not write a program in the sense of the program command for such a task. Instead you should use a .do file.
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment

            Working...
            X