# Stata旧笔记整理（一）

## 编写一个可以使用子样本及权重的命令

1. fweights: 频数权重, are weights that indicate the number of duplicated observations.
2. pweights: 抽样权重, are weights that denote the inverse of the probability that the observation is included because of the sampling design.
3. aweights: 分析权重, are weights that are inversely proportional to the variance of an observation; that is, the variance of the jth observation is assumed to be sigma^2/w_j, where w_j are the weights. Typically, the observations represent averages and the weights are the number of elements that gave rise to the average. For most Stata commands, the recorded scale of aweights is irrelevant; Stata internally rescales them to sum to N, the number of observations in your data, when it uses them.
4. iweights: 重要性权重, are weights that indicate the “importance” of the observation in some vague sense. iweights have no formal statistical definition; any command that supports iweights will define exactly how they are treated. Usually, they are intended for use by programmers who want to produce a certain computation.

## 创建虚拟变量

• gen
• gen + replace
• tab
• recode
• cond

## Stata15中新的宏扩展函数

rownumb & colnumb
rowsof & colsof
rowvarlist & colvarlist
rowfullnames & colfullnames

### rownumb&colnumb:返回字符串所在矩阵的行数和列数

• local lname: colnumb matrixname string
• local lname: rownumb matrixname string

### rowsof&colsof：返回矩阵的行数和列数

• local lname: rowsof matrixname
• local lname: colsof matrixname

Box-Muller方法：