Liz's Stata Guide

Commands: Datasets

This page covers commands that alter the structure of your dataset or allow you to combine two or more datasets.

The pages for many commands in this category need to be written / rewritten

Sorts the observations in a dataset according the value of a variable or variables.
sort varx vary

Changes how panel data (or panel-like data) is stored.
reshape wide varx vary, i(idvar) j(year)   - or -
reshape long varx vary, i(idvar) j(year)

Transposes the data so that each observation becomes a variable and each variable becomes an observation.

Makes Stata see if it can store your dataset more efficiently by changing the types of some variables.

order; move; aorder
Alters the order of the variables in a dataset, as they appear in the Variables window, or in commands like sum and list (when called with no arguements).
order idvar1 idvar2 varx vary varz   - or -
aorder idvar*   - or -
move varx vary

Joins two datasets containing different information (variables) on the same observations.
merge idvar using "files/otherdataset"

Joins two datasets containing different observations for the same variables.
append using "files/otherdataset"

last modified: 4 May 2007