Stata(一)
Stata官网帮助文档汇总:https://www.stata.com/features/documentation/
The complete contents for all manuals: https://www.stata.com/manuals/icombinedsubjecttableofcontents.pdf
[1]排序:(默认升序)
gsort A B
A, B 列名
主要关键字:A
次要关j键字:B
egen C = min(B), by(A)
令C中每个个体的各个观测值等于A列对应的每个个体最小的变量B的观测值。按照A列升序排列。
Stata has two built-in variables called _n and _N.
_n is Stata notation for the current observation number. _n is 1 in the first observation, 2 in the second, 3 in the third, and so on.
_N is Stata notation for the total number of observations.
When _n is combined with by, however, _n is the observation number within by-group
Example:
set obs 10
generate x = rnormal()
sort x
by x: generate cum = _N if _n==1
显示:
x cum
-2.260383 1
-1.975356 1
-1.735899 1
-1.655572 1
-1.585099 1
price 变量中最小的前10个数:
gsort +price
list make price in 1/10