Maybe my best advice is just to recite those four short sentences out loud every time you open Stata. But what does your fallibility imply for how you should code? Tal Gross has some excellent rules of thumb. I will summarize them below in case the link ever stops working.
- Use sensible names for variables and dofiles. For example, instead of calling a new variable "sex", call it "female".
- Comment everything! //You won't regret it!
- Make code readable. Put spaces before and after "+" and never ever put anything after a { or }. Go to the next line immediately.
- Create sections with ***************.
- Make code portable by making appropriate use of folders.
- Check your work. No, this doesn't mean reading lines and lines of code over and over again. It means things like summarizing variables right after creating them. Anything suspicious?
- Use a template.
- Preserve source data. Never ever change the original data source ever. Create new data files.
- Don't repeat yourself. Speaking of repeating myself, many of these tips are sounding familiar. I think I have blogged about this before. Yes, I have! Read here. That's Ok. These tips are worth repeating. Lines of code are not!
No comments:
Post a Comment