
A command to do so is: generate index = _n However, if you really want to do a stem-and-leaf plot you should always create a variable containing the original observation numbers (called “index”, for example).

The best way to avoid this problem is to avoid doing any stem-and-leaf plots (do histograms instead). The “stem” function seems to permanently reorder the data so that they are sorted according to the variable that the stem-and-leaf plot was plotted for. There is a glitch with Stata’s “stem” command for stem-and-leaf plots.

Produce a residual plot with horizontal line at 0:.Compute residuals, create new variable tt residuals:.Produce scatter plot with regression line added:.Compute predictions, create new variable yhat:.Compute simple regression line (vy is response, vx is predictor):.Normal data with mean mu and standard deviation sigma:.Normal data with mean 0 and standard deviation 1:.(These commands simulate rolling a six-sided die): Generate n discrete uniform random variables (equal chance of all outcomes between 1 and 6.Generate n uniform random variables (equal chance of all outcomes between a and b:.Generate n uniform random variables (equal chance of all outcomes between 0 and 1:.Set random number seed to XXXX, default is 1000:.Generate a variable with values 0 unless vtwo is greater than c, then make the value 1:.Multiply values in vx by b and add a, store results in vy:.Generate index of cases 1,2, ldots, n) (this may be useful if you sort the data, then want to restore the data to the original form without reloading the data):.Cross tabulate two variables, include one or more of the options to produce column, row or cell percents and to suppress printing of frequencies:.(The end of this command is minus 10/letter l.) To list the last 10 values for two variables:.To list the first 10 values for two variables:.To see all values (all variables and all observations, not recommended for large data sets):.To get more numerical summaries for one variable:.To compute means and standard deviations of select variables:.To compute means and standard deviations of all variables:.A scatter plot of two variables with the values of a third variable used in place of points on the graph (vthr might contain numerical values or indicate categories, such as male (m) and female (f)):.A matrix of scatter plots for three variables:.Plot side-by-side box plots for one variable (vone) by categories of another variable vtwo.Plot a histogram of a variable with a normal approximation:.Plot a histogram of a variable using frequencies:.Today I will teach you Common Stata Commands
