Sie sind auf Seite 1von 4

Useful STATA Commands

To increase memory size, type the following command (directly in the Command-window or run this line from a do-file): set mem 50m This increases data memory size to 50 MB, which should be enough. If it for some reason is not, just increase the value until you are able to open the data set. Do-files: To start a new do-file, click the New Do-file Editor-icon in the toolbar. To run lines of code, use short command Ctrl + d or click the Do-icon (the rightmost in the toolbar). When you run a do-file, highlight the lines of code you want to run, otherwise you run the whole file each time. To write explanatory text, start a line with * and then write your explanation (* tells Stata not to run this line of code, even if you highlight it). Operators in expressions When you for example create new variables or want to look at certain values of a variable, the following operators could be useful (see below for examples of how they can be used together with commands). Arithmetic
+ * / ^ addition subtraction multiplication division power & | !

Logical
and or not

Relational (numeric and string)


> < >= <= == != greater than less than greater than or equal to less than or equal to equal to not equal to

Note: A double equal sign (==) is used for equality testing. Some other important operators, such as if, can be written in words.

Descriptive and summary statistics etc.

The examples of syntax describe how the commands can be written in a do-file (the [ ]-

parentheses means that you have to insert something, for example the name of a variable). In some cases, I exemplify how operators can be used, but all commands could be used without any operators. However, all of the below commands have a lot of other options beside the basic syntax included here. For more information about what is possible to do with a certain command, search the Help-file by the name of the command. Codebook

Returns basic information about a variable, such as its type, range, percentiles, number of observations, mean etc. Basic syntax: codebook [varlist] Full syntax: codebook [varlist] [if] [in] [, options] Summarize

Returns summary statistics of a variable (min, max, sd, mean, nr of obs). Short name: sum. Basic syntax: sum [name of variable] Full syntax: summarize [varlist] [if] [in] [weight] [, options] Tabulate

Returns tables with frequencies or percentages. Basic syntax: tab [varlist] Full syntax: tabulate varname1 [varname2] [if] [in] [weight][, options] Sort

Reorder the data in ascending order. Basic syntax: sort [name of variable] List

Lists the individuals/firms on the screen by one or more conditions. Basic syntax: list [name of variable]

Replace

Change the values of a variable. basic syntax:

replace [name of variable] = [value] Example: replace [name of variable] = [value] if [name of other variable] == [value] & [name of other variable] == [value] Generate

Generate new variables. Basic syntax: gen [name of new variable] = [conditions for new variable] Example, syntax for creating a dummy variable with possible missing values: gen [name of new variable] = . replace [name of new variable] = 0 if [name of existing variable] < [cutoff point] replace [name of new variable] = 1 if [name of existing variable] >= [cutoff point]

Graphics
Tables and graphs could be made either by using the point and click options under the header Graphics in the main Stata window, or by using commands in do-files. Graphics Distributional graphs Histogram: choose variable, click discrete, choose Y- axis: Frequency To do the same thing in a do-file, write the following histogram [name of variable], discrete frequency

Correlation

The correlate command (short name: corr) displays the correlation matrix or covariance matrix for a group of variables or for the coefficients of the most recent estimation. If you do not specify a list of variables, the matrix is displayed for all variables in the data. Basic syntax:

corr [list of variables] The command pwcorr displays all the pairwise correlation coefficients between the

variables in a list of variables or, if no list is specified, all the variables in the dataset. pwcorr [list of variables]

Das könnte Ihnen auch gefallen