STATA实用学习笔记
北京科技大学
STATA应用
学习摘录
第一章 STATA的基本操作
一、设置内存容
set mem 500m, perm 一、 显示输入内容
Display 1
Display “clive”
二、 显示数据集结构describe
Describe /d 三、 编辑 edit
Edit 四、 重命名变量
Rename var1 var2
五、 显示数据集内容list/browse
List in 1 List in 2/10
六、 数据导入:数据文件是文本类型(.csv)
1、 insheet: . insheet using “C:\\Documents and Settings\\Administrator\\桌面
\\ST9007\\dataset\\Fees1.csv”, clear
2、 内存为空时才可以导入数据集,否则会出现(you must start with an empty dataset)
(1) 清空内存中的所有变量:.drop _all (2) 导入语句后加入“clear”命令。
七、 保存文件
1、 save “C:\\Documents and Settings\\Administrator\\桌面\\ST9007\\dataset\\Fees1.dta”
2、 save “C:\\Documents and Settings\\Administrator\\桌面\\ST9007\\dataset\\Fees1.dta”, replace 八、 打开及退出已存文件use
1、.Use 文件路径及文件名, clear 2、. Drop _all/.exit
九、 记录命令和输出结果(log)
1、 开始建立记录文件:log using \2、 暂停记录文件:log off 3、 重新打开记录文件:log on 4、 关闭记录文件:log close 十一、创建和保存程序文件:(doedit, do)
1、 打开程序编辑窗口:doedit 2、 写入命令
3、 保存文件,.do.
4、 运行命令:.do 程序文件路径及文件名
十二、多个数据集合并为一个数据集(变量和结构相同)纵向合并append
insheet using \save \
insheet using \
2
append using \save \
十三、横向合并,在原数据集基础上加上另外的变量merge
1、insheet using \
sort companyid yearend
save \describe
insheet using \sort companyid yearend
merge companyid yearend using \save \describe
2、_merge==1 obs. From master data _merge==2 obs. From using data
_merge==3 obs. From both master and using data
十四、帮助文件:help 1、. Help describe 十五、描述性统计量
1、summarize incorporationyear 单个
summarize incorporationyear-big6 连续多个 summarize _all or simply summarize 所有
2、更详细的统计量
summarize incorporationyear, detail 3、centile
centile auditfees, centile(0(10)100) centile auditfees, centile(0(5)100)
4、tabulate不同类型变量的频数和比例
tabulate companytype
tabulate companytype big6, column 按列计算百分比 tabulate companytype big6, row 按行计算百分比
tab companytype big6 if companytype<=3, row col 同时按行列和条件计算百分比
5、 计算满足条件观测的个数
count if big6==1
count if big6==0 | big6==1 6、按离散变量排序,对连续变量计算描述性统计量:
(1)by companytype, sort: summarize auditfees, detail (2)sort companytype
By companytype:summarize auditees
十六、转换变量
1、按公司类型将公开发行股票公司赋值为1,其他为0 gen listed=0
replace listed=1 if companytype==2
3
replace listed=1 if companytype==3 replace listed=1 if companytype==5 replace listed=. if companytype==.
十七、产生新变量gen
Generate newvar=表达式 十八、数据类型 1、数值型 Storage type Bytes byte int long float double 2、字符型 Storage type str1 str2 … str80 Bytes 1 2 80 Max length (characters) 1 2 80 1 2 4 4 8 Min -127 -32,767 -2,147,483,647 -1.70141173319*1038 -8.9884656743*10307 Max +100 +32,740 2,147,483,620 1.70141173319*1036 8.9884656743*10308 3、新建变量的过程中定义数据类型
? gen str3 gender= \? list gender in 1/10
4、变量所占字节过长
? drop gender
? gen str30 gender= \? browse
? describe gender ? compress gender
5、日期数据类型:%d dates, which is a count of the number of days elapsed since January 1, 1960。 (1)date( 日期变量 )
? gen fye=date(yearend, \应根据前面日期的排列顺序而定,结果显示的
是距离1960年1月1日的天数 ? list yearend fye in 1/10
(2)日期格式化%d(显示fye变量为日期形式,但数值并未真正变动):
? format fye %d
? list yearend fye in 1/10
4
? sum fye
(3)利用日期天数求对应的年、月、日
? gen year=year(fye) ? gen month=month(fye) ? gen day=day(fye)
? list yearend fye year month day in 1/10 (4)将三个分别表示年、月、日的变量合并为一个日期变量
? drop fye
? gen fye=mdy(month, day, year) ? format fye %d
? list yearend fye in 1/10
(5) 将一个数值型的时间数据(20080131)转变为ST可识别的时间数据
? gen year=int(date/10000)
? gen month=int((date-year*10000)/100) ? gen day=date-year*10000-month*100 ? list date year month day in 1/10 ? gen edate=mdy(month, day, year) ? format edate %d ? list edate date in 1/10
十九、存贮统计量的内部变量R( )
? sum auditfees
? gen meanadjaf= auditfees-r(mean) ? list meanadjaf in 1/10
SUM命令后常见的几种R()值 r(N) r(sum_w) r(mean) r(var) Number of cases Sum of weights Arithmetic mean Variance r(sd) r(min) r(max) r(sum) Standard deviation Minimum Maximum Sum of variable 显示这些变量值的命令
? sum auditfees, detail ? return list
二十、recode命令(PPT61)
1、产生有多个值的变量的哑变量recode
recode year (min/1999 = 0) (2000/max = 1), gen (yeardum) min/1999表示小于等于1999的值全部赋值为0 2000/max表示大于等于2000的值全部赋为1。
2、对一个连续变量按一定值分为不同间隔的组recode
gen assets_categ=recode(totalassets, 100, 500, 1000, 5000, 20000, 100000, 1000000)。分组的值为每组的上限,包含该值。 sort assets_categ
5
…… 此处隐藏:2095字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [实用模板]第八章:法国“新浪潮”与“左岸派”
- [实用模板]2021年北京上半年临床医学检验技师生物
- [实用模板]SAP GUI 7.10客户端安装配置文档
- [实用模板]2001年临床执业医师资格考试综合笔试试
- [实用模板]36机场工作实用英语词汇总结
- [实用模板](一)社会保险稽核通知书
- [实用模板]安全教育主题班会材料
- [实用模板]濉溪县春季呼吸道传染病防控应急演练方
- [实用模板]长沙房地产市场周报(1.30-2.3)
- [实用模板]六年级数学上册典中点 - 图文
- [实用模板]C程序设计(红皮书)习题官方参考答案
- [实用模板]中国证监会第一届创业板发行审核委员会
- [实用模板]桥梁工程复习题
- [实用模板]2011学而思数学及答案
- [实用模板]初中病句修改专项练习
- [实用模板]监理学习知识1 - 图文
- [实用模板]小机灵杯四年级试题
- [实用模板]国贸专业毕业论文模板
- [实用模板]教育学概论考试练习题-判断题4
- [实用模板]2015届高考英语一轮复习精品资料(译林
- 00Nkmhe_市场营销学工商管理_电子商务_
- 事业单位考试法律常识
- 诚信教育实施方案
- 吉大小天鹅食品安全检测箱方案(高中低
- 房地产销售培训资料
- 高一地理必修1复习提纲
- 新概念英语第二册lesson_1_练习题
- 证券公司内部培训资料
- 小学英语时间介词专项练习
- 新世纪英语专业综合教程(第二版)第1册U
- 【新课标】浙教版最新2018年八年级数学
- 工程建设管理纲要
- 外研版 必修一Module 4 A Social Surve
- Adobe认证考试 AE复习资料
- 基于H.264AVC与AVS标准的帧内预测技术
- 《食品检验机构资质认定管理办法》(质
- ABB变频器培训课件
- (完整版)小学说明文阅读练习题及答案
- 深思洛克(SenseLock) 深思IV,深思4,深
- 弟子规全文带拼音




