*Stata programming by Example *Tutorial 1 * writing Stata programs can be done in the Stata do editor * to open the do editor type the following on the Stata command line doedit //opens do editor *or use the "New Do-File Editor" Icon **Example 1, this runs a few Stata commands *--------------Start Example 1 ----------------* sysuse auto, clear //loads auto dataset after clearing existing data from computer memory describe summarize *--------------End Example----------------------* *Example 2 - This starts a do file from the Stata commandline *You need to do the following to get this to run: ***copy Example2 (below) to a new page on the do editor, by doing: *****highlight example 2 *****right click to copy *****press blank page icon on the do editor *****right click to paste *Then save file eg. press floppy disc icon and give it a location and name (save as a .do extension) *Then to run Example 2 as a saved do file: *****type on the Stata commandline "do" and the file name (file path if necessary) *****eg. assuming that the just saved do file is in c:/data , this is what you would type: do c:/data/example2 *--------------Start Example 2 ----------------* sysuse auto, clear //loads auto dataset after clearing existing data from computer memory describe summarize *--------------End Example----------------------* *After having first done example 2 then you can do example 3. This runs a do file from the Stata do editor *--------------Start Example 3 ----------------* do c:/data/example2 //the do file path and name must correspond with that given in example 2 *--------------End Example----------------------* *see help do *Save example 4 the same way as you did for example 2. But to run this also type a variable *name *eg. do c:/data/example4 mpg *--------------Start Example 4 ----------------* sysuse auto, clear //loads auto dataset after clearing existing data from computer memory describe summarize `1' *--------------End Example----------------------* *see Stata 10 Users Guide 16.6.1 *Save example 5 the same way as you did for example 2. But to run this type also type a variable *name *eg. do c:/data/example5 mpg price *--------------Start Example 5 ----------------* sysuse auto, clear //loads auto dataset after clearing existing data from computer memory describe `1' summarize `1' `2' *--------------End Example----------------------* *End tutorial 1 - programming Stata