******************************************************************************** * * * Program: Class2.do * * Purpose: Illustrate a basic batch program * * * ********************************************************************************; ******************************************************************************** * * * Reset "end-of-command" delimiter using the #delimit command * * #delimit is a Stata preprocessor command. #commands do not generate a * * return code, nor do they generate ordinary Stata errors. * * * ********************************************************************************; #delimit ; ******************************************************************************** * * * Clear the memory and change working directory * * * ********************************************************************************; cd "C:\stemp"; clear; ******************************************************************************** * * * Start log and open data set of interest: Caschool.do * * * ********************************************************************************; log using class2.log,replace; set more off; use caschool.dta; ******************************************************************************** * * * Describe the dataset using the "describe" command * * Command format: describe [varlist] [, memory_options] * * Command purpose: produces a summary of the dataset in memory or of the * * data stored in a Stata-format dataset. * * * ********************************************************************************; describe; ******************************************************************************** * * * Construct summary statistics for the dataset using "summarize" command * * Command format: summarize [varlist] [if] [in] [weight] [, options] * * Command purpose: summarize calculates and displays a variety of * * univariate summary statistics. If no varlist is * * specified, summary statistics are calculated for all * * the variables in the dataset. * * * ********************************************************************************; summarize; summarize testscr str, detail; summarize testscr if str>20; summarize testscr if str<=20; ******************************************************************************** * * * Generate discrete counterparts to testscr and str variables * * Command format: generate [type] newvar[:lblname] =exp [if] [in] * * Command purpose: generate creates a new variable. The values of the * * variable are specified by =exp. * * * ********************************************************************************; generate hightscr = testscr>654; generate highstr = str>20; ******************************************************************************** * * * Generate cross tabulation table for discrete variables * * Command form: tabulate varname1 varname2 [if] [in] [weight] [, options]* * Command purpose: tabulate produces two-way tables of frequency counts, * * along with various measures of association * * * ********************************************************************************; tabulate hightscr highstr; ******************************************************************************** * * * Investigate correlation among variables "correlation" command * * Command format: correlate [varlist] [if] [in] [weight] [, options] * * Command purpose: The correlate command displays the correlation matrix * * or covariance matrix for a group of variables or for * * the coefficients of the most recent estimation. If * * varlist and _coef are not specified, the matrix is * * displayed for all variables in the data. * * * ********************************************************************************; cor testscr str; ******************************************************************************** * * * Graph relationship between student teach ratio and test scores * * Command format: [graph] twoway plot [if] [in] [, twoway_options] * * Command purpose: twoway is a family of plots, all of which fit on * * numeric y and x scales. * * * ********************************************************************************; twoway (scatter testscr str); ******************************************************************************** * * * Close log file, clear memory and exit Stata * * * ********************************************************************************; log close; clear; exit;