admin管理员组

文章数量:1536061

STATA学习笔记:函数

1. programming functions

(1)定义虚拟变量:inlist(z,a,b,…)

sysuse nlsw88.dta, clear
des2 industry
//【out】industry是类别变量



1 Ag/Forestry/Fisheries
Ag/Forestry/Fisheries是变量值"1"的标签

gen dummy = inlist(industry, 7,8,11) 
//inlist(industry,7,8,11)中的industry是类别变量名
//7,8,11是以数字形式枚举
//如果industry变量值是7,8,11中的一个,新生成的虚拟变量值取1,否则取0

br industry dummy, nolabel

br industry dummy

2.string functions

(1)tostring

tostring converts variables in varlist from numeric to string.

webuse tostring, clear

(2)destring

destring year,replace
br

3.random_number functions

set obs 1000
//设置观察值个数
gen y_u = runiform()
gen y_n = rnormal()
gen y_p = poisson(6)

本文标签: 函数学习笔记stata