# Stata/Data Management

Stata
* Basics
** Introduction
** Settings
** Documentation
** Probability Function
** Random Number Generation
** Data Management
** Graphics
** Programming
** Mata
** Natural Language Processing
** Publication Quality Output
** Descriptive Statistics
* Methods
** Maximum Likelihood
** Bayesian Methods
** Bootstrap
** Non Parametric
** Matching
** Quantile Regression
* Topics
** Linear Models
** Binomial Outcome Models
** Multinomial Models
** Count Data Models
** Tobit and Selection Models
** Duration Analysis
** Multilevel Modeling
** Time Series
** Spatial Econometrics
** Factor Analysis
* Problems

## Read and import data

Usually, data are loaded into memory using the use command. The clear option makes it sure that the current database in memory will be removed without saving the last changes.
The cd command allows to specify a working directory and makes it easier to load tables into memory.
Stata9 users can import Stata10 datasets using the use10 command.
Some example datasets are stored in the Stata directory. They can be loaded into memory using the sysuse command.
You can import a Comma Separated Value (CSV) format using insheet

### See also

* 'webuse' for internet data
* 'xmluse' for xml files
* 'infile' for text files
* 'input' for entering data from keyboard
* 'infix'
* 'fdause' for SAS xport data
* If none of these command works, you may use Stat/Transfer
* FTRANS: module to batch convert file formats

## Save and export data

* save
If you use Stata10 you can export to Stata9 format using saveold
* outsheet : export to tab delimited or csv format.
See also
* outfile
* xmlsave
* fdasave

## Append and merge

The standard Stata command is merge. However, the user-written command mmerge is safer and gives a better output. This command may be installed using ssc install mmerge command or using findit mmerge.
* dmerge
* joinby merge all possible pairs between the datasets
* append if you have two datasets with the same variable but different observations, you can make one dataset using the append command.

## Describe a datasets

* des
* des, s
* codebook
* codebook2

## Detect missing values

* tabmiss
* npresent
* nmissing
You can convert missing values to values using the mvencode command.

## Variables

Very often you have to convert variable from a string to a numerical format. There are several way to do it. If you already have numeric values in your string variable, you should use destring. Otherwise you should use the encode command. Encode will automatically create a numerical variable and will use as a value label the string values of the previous variable.
* gen
* egen
* replace
* recode
* drop
* keep
* rename
'vallist' gives the list of all categories of a categorical variable in Stata.

## Dealing with labels

* lab var
* lab list
* lab define
* lab value

## Expand

* You can expand a dataset (ie multiplying observations by a given factor) using the expand command.
This is useful for generating panel data models. In the first example, we draw 10 observations in a standard normal distribution and we replicate each observation once.
It is also possible to pass an integer variable as an argument to expand.

## Data Storage types

All numeric types in Stata are normal "signed" quantities except that the highest 27 values are reserved for the "missing" types (., .a, .b, ..., .z). The storage size of the each variable is as follows:
| Variable | Size (in bytes) |
| byte | 1 |
| int | 2 |
| long | 4 |
| float | 4 |
| double | 8 |
| string | 1 per-letter (therefore only ASCII characters, not full Unicode/UTF-8) |