Announcement

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

  • Good sources for learning about Stata macros?

    Do y'all have recommendations on the best place to point students who have rudimentary Stata familiarity to get them up and running on Stata macros, looping, and the like?

    Google turns up a million web pages, documents, and videos; I'm just curious if people have resources they find particularly effective.

    Thanks!

  • #2
    The Stata documentation, perhaps?

    Start with Chapter 18 of the Stata User's Guide PDF—"Programming Stata", which inclodues a section on macros. The Stata documentation has, since version 11 or so, been included in the Stata installation and is accessible from Stata's Help menu.

    My own belief is that students would be well advised to read through the Getting Started with Stata manual relevant to their setup, and after doing so, look at Chapter 18 of that manual, which gives suggested further reading, much of which, like the material on programming Stata, is in the Stata User's Guide.

    Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I describe surfaces the things one need to know to get started in a hurry and to work effectively.

    Comment


    • #3
      On top of William's excellent advice, once you become comfortable with macro programming, it can pay to study existing macros for typo and tricks. You can view macro source code using -viewsource-.
      Last edited by Leonardo Guizzetti; 25 Jan 2019, 21:50.

      Comment


      • #4
        Here's a webpage on programming in Stata, starting with macros: https://www.ssc.wisc.edu/sscc/pubs/stata_prog1.htm

        In my experience, people who work in user support settings like the authors of the preceding provide an easier starting point than Stata's documentation for the beginner.

        Comment


        • #5
          I second William's encouragement to use the Stata documentation. While there is a lot of documentation, the manuals are very well written and more accessible than those for any other statistical program.

          A (very!) long time ago, I invested in Stata NetCourse 151. This was before the ample free resources on the web (indeed, the NetCourse was conducted over email at the time). While it seemed like a hefty fee for a poor grad student, it was extraordinarily useful.
          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment


          • #6
            I d say reading the manual on loops and macros swiftly, and reading Stata Journal (Stata Tips and Speaking Stata columns of Nick Cox) would be the way to start. Then as people do macros in their own work, they come back and read the manual in more detail.

            Comment


            • #7
              I agree with Mike that the writing of user support staff can be more approachable than Stata's documentation.

              But I cringe at the examples on the linked page of looping over variables in a wide layout panel dataset, followed by a discussion of accomplishing the same thing without loops by reshaping long and then reshaping back to a wide layout, with no acknowledgement of the unsuitability of a wide layout for most analyses of panel data. That discussion ends with the advice

              Reshaping a large data set is time consuming, so don't switch between wide form and long form lightly. But if you can identify a block of things you need to do that would be easier to do in long form, it may be worth reshaping at the beginning and end of that block.
              I think this page was written by someone who in 2012 understood macros and looping, but did not thoroughly understand statistical analysis of panel data.

              On the other hand, and I am quite serious about this, in that document the local macro dereferencing characters
              Code:
              ` and '
              look exactly like they do when viewed in Stata, unlike StataCorp's insistence on using in their PDFs the typographical left and right "single quotes" rather than the "accent grave" and "apostrophe" characters users must type for Stata to recognize them.

              Had I remembered this problem, I would have been less likely to make the initial recommendation I did in post #2. I still feel fairly strongly, though, that users moving into Stata programming should familiarize themselves with the Stata documentation.

              I guess I would recommend the page Mike references, but warn the students that the example wide layout panel data is for pedagogic purposes, and a long layout is generally to be preferred.

              Comment


              • #8
                Thanks, all. I had already directed my students to the Stata documentation, which I agree is excellent.

                That Wisconsin page is good, though I agree that some time spent mastering -reshape- is well worth it. Once you internalize it, it's amazing what it can do...

                Comment


                • #9
                  I think William Lisowski 's diagnosis of the Wisconsin page is spot on: The author is good at explaining, but not very knowledgeable about dealing with panel data in Stata. And, the "time consuming" seems offbase, even with 2012 machines.

                  I have had quite a bit of experience trying to get beginners to read Stata's -help- files, and I have not had them respond positively. I just don't think that technical documentation works for very many people at the start of their experience, and I also think that there's a cultural issue here, namely a widespread belief that everything can be learned experientially rather than by reading first <grin>. Now, for students with previous statistical package or other programming experience, the documentation would be a lot more helpful.

                  Comment


                  • #10
                    Originally posted by Mike Lacy View Post
                    I have had quite a bit of experience trying to get beginners to read Stata's -help- files, and I have not had them respond positively.
                    If you do mean the help output, rather than the documentation path I described in post #2, then I somewhat agree with the students. Trying to learn Stata by reading the output of the help command, perhaps for a command randomly chosen from the output of the search command, is like trying to learn French from a French-to-English (but not the reverse) dictionary.

                    Perhaps StataCorp needs to reformulate Stata to be more like an experiential video game (e.g. Fortnite) with rewards for each new command you get to work successfully, and in-app purchases of expertise that involve the transfer of real-world money to the suppliers (*cough* Statalist *cough*),

                    My guess about the genesis of the Wisconsin page was the result of running a user support group at a research institution for several years in a much earlier life. We had to take care to have documentation reviewed from multiple perspectives to reduce just this sort of oversight. And let's face it, someone who's good at panel data analysis is not likely to be writing documentation on foreach loops, other than at StataCorp in the early days, when, or so I've read, Bill Gould did user support, Bill Rogers did user support.

                    Comment


                    • #11
                      So, while we're adding resources, I thought I would add the following:

                      Articles from Stata Journal:
                      Speaking Stata: How to face lists with fortitude (Nick Cox, 2002). Link
                      Speaking Stata: Problems with lists (Nick Cox, 2003) Link

                      These 3 intros to Stata programming:
                      Chris Baum, A little bit of Stata programming goes a long way... Link
                      Manuel Barron, Stata Programming Link
                      German Rodriguez, Programming Stata Link

                      I ended up purchasing Chris Baum's book, "An Introduction to Stata Programming", and found it to be excellent. Link

                      Comment

                      Working...
                      X