STATA实用学习提高笔记材料

上传人:不*** 文档编号:93090988 上传时间:2019-07-16 格式:DOC 页数:39 大小:1.02MB
返回 下载 相关 举报
STATA实用学习提高笔记材料_第1页
第1页 / 共39页
STATA实用学习提高笔记材料_第2页
第2页 / 共39页
STATA实用学习提高笔记材料_第3页
第3页 / 共39页
STATA实用学习提高笔记材料_第4页
第4页 / 共39页
STATA实用学习提高笔记材料_第5页
第5页 / 共39页
点击查看更多>>
资源描述

《STATA实用学习提高笔记材料》由会员分享,可在线阅读,更多相关《STATA实用学习提高笔记材料(39页珍藏版)》请在金锄头文库上搜索。

1、北京科技大学STATA应用学习摘录第一章 STATA的基本操作 一、设置内存容 set mem 500m, perm一、 显示输入内容Display 1Display “clive”二、 显示数据集结构describeDescribe /d三、 编辑 editEdit四、 重命名变量Rename var1 var2五、 显示数据集内容list/browseList in 1List in 2/10六、 数据导入:数据文件是文本类型(.csv)1、 insheet: . insheet using “C:Documents and SettingsAdministrator桌面ST9007dat

2、asetFees1.csv”, clear2、 内存为空时才可以导入数据集,否则会出现(you must start with an empty dataset)(1) 清空内存中的所有变量:.drop _all(2) 导入语句后加入“clear”命令。七、 保存文件1、 save “C:Documents and SettingsAdministrator桌面ST9007datasetFees1.dta”2、 save “C:Documents and SettingsAdministrator桌面ST9007datasetFees1.dta”, replace八、 打开及退出已存文件use

3、1、.Use 文件路径及文件名, clear2、. Drop _all/.exit九、 记录命令和输出结果(log)1、 开始建立记录文件:log using J:phdoutput.log, replace2、 暂停记录文件:log off3、 重新打开记录文件:log on4、 关闭记录文件:log close十一、创建和保存程序文件:(doedit, do)1、 打开程序编辑窗口:doedit2、 写入命令3、 保存文件,.do.4、 运行命令:.do 程序文件路径及文件名十二、多个数据集合并为一个数据集(变量和结构相同)纵向合并appendinsheet using J:phdFees

4、1.csv, clearsave J:phdFees1.dta, replaceinsheet using J:phdFees2.csv, clearappend using J:phdFees1.dtasave J:phdFees1.dta, replace十三、横向合并,在原数据集基础上加上另外的变量merge1、insheet using J:phdFees1.csv, clearsort companyid yearend save J:phdFees1.dta, replacedescribeinsheet using J:phdFees6.csv, clearsort compan

5、yid yearend merge companyid yearend using J:phdFees1.dtasave J:phdFees1.dta, replacedescribe 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

6、-big6 连续多个summarize _all or simply summarize 所有 2、更详细的统计量 summarize incorporationyear, detail 3、centilecentile auditfees, centile(0(10)100) centile auditfees, centile(0(5)100) 4、tabulate不同类型变量的频数和比例tabulate companytype tabulate companytype big6, column 按列计算百分比tabulate companytype big6, row 按行计算百分比ta

7、b companytype big6 if companytype=3, row col 同时按行列和条件计算百分比 5、 计算满足条件观测的个数 count if big6=1count if big6=0 | big6=1 6、按离散变量排序,对连续变量计算描述性统计量:(1)by companytype, sort: summarize auditfees, detail(2)sort companytype By companytype:summarize auditees 十六、转换变量1、按公司类型将公开发行股票公司赋值为1,其他为0gen listed=0 replace lis

8、ted=1 if companytype=2 replace listed=1 if companytype=3 replace listed=1 if companytype=5replace listed=. if companytype=.十七、产生新变量gen Generate newvar=表达式十八、数据类型1、数值型Storage typeBytesMinMaxbyte1-127+100int2-32,767+32,740long4-2,147,483,6472,147,483,620float4-1.70141173319*1038 1.70141173319*1036 dou

9、ble8-8.9884656743*103078.9884656743*103082、字符型Storage typeBytesMax length (characters)str111str222str8080803、新建变量的过程中定义数据类型l gen str3 gender= malel list gender in 1/104、变量所占字节过长l drop genderl gen str30 gender= malel browsel describe genderl compress gender5、日期数据类型:%d dates, which is a count of the n

10、umber of days elapsed since January 1, 1960。(1)date( 日期变量 )l gen fye=date(yearend, MDY) MDY应根据前面日期的排列顺序而定,结果显示的是距离1960年1月1日的天数l list yearend fye in 1/10(2)日期格式化%d(显示fye变量为日期形式,但数值并未真正变动):l format fye %d l list yearend fye in 1/10l sum fye(3)利用日期天数求对应的年、月、日l gen year=year(fye)l gen month=month(fye)l

11、gen day=day(fye)l list yearend fye year month day in 1/10(4)将三个分别表示年、月、日的变量合并为一个日期变量l drop fyel gen fye=mdy(month, day, year)l format fye %dl list yearend fye in 1/10(5) 将一个数值型的时间数据(20080131)转变为ST可识别的时间数据l gen year=int(date/10000)l gen month=int(date-year*10000)/100)l gen day=date-year*10000-month*1

12、00l list date year month day in 1/10l gen edate=mdy(month, day, year)l format edate %dl list edate date in 1/10十九、存贮统计量的内部变量R( )l sum auditfeesl gen meanadjaf= auditfees-r(mean) l list meanadjaf in 1/10SUM命令后常见的几种R()值r(N)Number of casesr(sd)Standard deviationr(sum_w)Sum of weightsr(min)Minimumr(mean

13、)Arithmetic meanr(max)Maximumr(var)Variancer(sum)Sum of variable显示这些变量值的命令l sum auditfees, detaill return list二十、recode命令(PPT61)1、产生有多个值的变量的哑变量recoderecode year (min/1999 = 0) (2000/max = 1), gen (yeardum)min/1999表示小于等于1999的值全部赋值为02000/max表示大于等于2000的值全部赋为1。2、对一个连续变量按一定值分为不同间隔的组recodegen assets_categ

14、=recode(totalassets, 100, 500, 1000, 5000, 20000, 100000, 1000000)。分组的值为每组的上限,包含该值。sort assets_categby assets_categ: sum totalassets assets_categ 3、 对一个连续变量按一定值分为相同间隔的组autocodeautocode(variable name, # of intervals, min value, max value)for example: gen assets_categ=autocode(totalassets, 10, 0, 10000)4、对一个连续变量按每组样本数相同进行分组:xtilextile assets_categ=totalassets, nquantiles(10)每组样本不一定完全相同二十一、一次性计算同一变量不同组别的均值:egen命令按公司类型先排序,再计算每一类型公司审计费用的均值并赋值给新变量:by companytype, sort: egen meanaf2=me

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 教育学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号