基本命令、蒲丰投针与随机数生成

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

常用命令
tabstat mpg tabstat mpg, stat(n mean sd) tabstat price mpg headroom trunk tabstat price mpg headroom trunk,stat(n mean sd) tabstat price mpg headroom trunk,stat(n mean sd min max) sort foreign
常用命令
• 统计性质列表 tabstat;table; tabulate table rep78 table rep78, content(n mpg mean mpg sd mpg median mpg) table rep78, content(n mpg mean price) table rep78 foreign table foreign rep78,content(mean mpg) row col
tabstatpricempgtabstatpricempgbyforeigntabstatpricempgbyforeignnototaltabstatpricempgbyrep78tabulaterep78tabulaterep78sorttabrep78genrep常用命令destabrep78foreign?改变变量排列顺序orderkeepmakepricempgrep78orderpricerep78makempg常用命令?另一个重要的生成变量命令egen?改变数据类型format常用命令stata保存的数据类型byteintlongfloatdoublestr数据显示格式ggcffcsttcdatetime
常用命令
label list ori label copy ori orig label define orig 2 " ",add label define orig 2 "don't know", modify replace foreign=2 if mod(_n,10)==4 label values foreign orig label save orig using mylabel type mylabel.do
COPY RIGHT: DR. CHUNTAO LI leechtcn@
4
copy 命令
• • • • copy orig.dta newcopy.dta copy "my document" "copy of document“ copy ..\mydir\doc.txt document\doc.tex copy /examples/simple.dta d:\simple.dta • copy /examples/simple.txt d:\simple.txt, text
常用命令
• 变量标签 label
clear all sysuse auto des label data 1978汽车调查数据 des label data "***1978汽车调查数据" des label data " " des
常用命令
label variable mpg "mile age" label variable foreign “car_type“ label list label dir label list label drop origin label define ori 0 "Domestic" 1 "Foreign" label list
常用命令
• 显示文件内容 type type stk_price.txt type temp.txt • 删除数据(从文件夹)erase erase newcopy.dta erase stk_price.dta
常用命令
• 简单的查看整体数据统计性质 describe; summarize clear sysuse auto des sum by foreign: sum by foreign: sum price mpg rep78, detail
常用命令
• Stata运算符号 +,-,*,/,^, sqrt(), exp(), ln(), log(), log10() , max(), min(), mod(), int(), round() • 计算器 display
常用命令
• 生成新变量 generate
generate [type] newvar=exp [if] [in] .sysuse auto .gen p2=sqrt(price) .gen n_v1=price*mpg .replace p2=int(p2) .gen n_v2=price*length if foreign==1 . by foreign: generate n_v3=gear_ratio if _n==_N
有用的网站
• /stataprogram • /stat/stata/ •
COPY RIGHT: DR. CHUNTAO LI leechtcn@
3
DOS命令
• • • • • • mkdir dir cd erase type copy
常用命令
keep in 5/54 keep if price>7000 • 删除数据 clear use stk_price mat A=mat(1,2,3\2,3,4) clear mat l A clear all ; matort、gsort
clear all sysuse auto des sort price list make price in 1/10 list make price in -10/-1 list foreign price in -10/-1 gsort -price list make price in 1/10
COPY RIGHT: DR. CHUNTAO LI leechtcn@
5
常用命令
• • • • • • • • order codebook compare inspect browse dedit sort which
COPY RIGHT: DR. CHUNTAO LI leechtcn@ 6
帮助系统
• 系统帮助 help • 网络帮助 findit google • 专家帮助 /access/statlist majordomo@ /subscribe statlist statlist@
33
随机函数
• • • • • • • gen r1 = runiform() gen r2 = rnormal() gen r3 = rnormal(5,2) gen r3 = 5 + 2 *rnormal() gen r3 = 5 + 2 * invnorm(runiform()) gen r4 = rchi2(27) gen r5 = rt(27)
常用命令
by foreign:tabstat price mpg tabstat price mpg, by(foreign) tabstat price mpg, by(foreign) nototal tabstat price mpg, by(rep78) tabulate rep78 tabulate rep78, sort tab rep78, gen(rep)
常用命令
• 数个数 count count count if rep78==. count if price>6165 count if foreign==0
常用命令
• 计算变量平均数 ameans;mean, over( ) ameans price ameans price, add(1000) level(99) mean price mpg headroom trunk mean price mpg headroom, over(foreign) mean price mpg headroom, over(rep78) sort rep78 by rep78: ameans price mpg headroom
COPY RIGHT: DR. CHUNTAO LI leechtcn@ 8
常用命令
• • • • • • • list drop keep generate replace rename egen
COPY RIGHT: DR. CHUNTAO LI leechtcn@ 9
运算符
数学运算符 + * / ^ + 数学加 数学减 数学乘 数学除 乘方 负号 字符串加 & | ! ~ 逻辑运算符 逻辑与 逻辑或 逻辑非 逻辑非 > < >= <= == != ~= 关系运算符 大于 小于 大于或等于 小于或等于 等于 不等于 不等于
COPY RIGHT: DR. CHUNTAO LI leechtcn@
常用命令
• 修改变量名 rename sysuse auto rename make car_make rename price pi rename mpg car_mpg save D:\new_auto.dta, replace
常用命令
• 复制文件 copy cd D:\ dir copy auto.dta copy_auto.dta dir copy temp.txt copy_temp.txt copy temp.do copy_temp.do dir
常用命令
label drop orig label dir do mylabel label dir
常用命令
• 删除变量 drop/keep,(in/if) clear all sysuse auto drop make drop in 4 drop if foreign==1 keep price mpg rep78 headroom trunk turn displacement gear_ratio foreign
常用命令
• 输入数据 input /直接在数据编辑窗口输入 • 读入数据 use、insheet using • 查看工作路径 cd ; dir
常用命令
• 保存、输出数据 save、outsheet using • 查看数据 list (in/if),table/display ;browse/edit(in/if) • 更替数据 replace
帮助
• Help 系统
– Stata的每一个命令都有一个对应的帮助文件 – help help – help regress – help summarize – help function – help tabulate – help generate – help matrix
COPY RIGHT: DR. CHUNTAO LI leechtcn@ 1
COPY RIGHT: DR. CHUNTAO LI leechtcn@ 34
重要的数字
• • • • c(pi) or _pi exp(1) c(current_time) c(current_date)
常用命令
des tab rep78 foreign • 改变变量排列顺序 order keep make price mpg rep78 order price rep78 make mpg
常用命令
• 另一个重要的生成变量命令 egen • 改变数据类型 format
常用命令
stata 保存的数据类型 byte int long float double str# 数据显示格式 %g %gc %f %fc %s %t %tc date/time;%td date;%tw week %tm month;%tq quarter;%th halfyear %ty year ;%tg generic
compare
• webuse fullauto, clear • compare rep78 rep77
COPY RIGHT: DR. CHUNTAO LI leechtcn@
7
cf
• • • • • • • sysuse auto drop gear_ratio replace mpg = 20 in 1/2 replace rep78 = 6 in 3 save mycf sysuse auto cf _all using mycf
相关文档
最新文档