2、Stata入门---如何保证分析的可重复性

如何保证分析的可重复性

1、Log File

所有显示在results上的结果都保存为文档形式
类似于R markdown文件


Log命令

log using filename [, append replace [text | smcl] name(logname)

  • append:如果文件存在,附加(append)在文件上
  • replace:如果文件存在,替换(replace)该文件
    如果文件不存在,append、replace都会自动创建一个文件。
  • smcl:Stata默认的log文件格式,可以保存各种颜色信息(报错、标记)
  • text:单色,便于在文本编辑器中打开,适合发给别人看
log using jim, name(log_for_jim)  //起别名,括号里面为别名,jim为文件名
 log using mark, name(log_for_mark) //起别名,括号里面为别名,mark为文件名

关闭文件

log close     //关闭未命名的文件
log close log_for_jim    //只关闭jim文件
log close _all             //关闭所有起名字的和未取名字的。
Do File

合作者
提醒自己
存档

2、Do File命令

创建do-file文件
/*
Read Me Flie:
    Stata Version     :     15.0
    Date Created      :     2022-04-12(Matthew)
    Data last modified:     2022-04-12(Matthew)
    For exploratory:  :     Yes
    For manuscript    :     No
    Should install    :     ssc install fre
    Note:
        This do-file is for generating the dataset for...       
*/
clear all //清除所有的东西,数据源
pwd   //获取当前的工作路径,Get the current working directory
log using "test_note", replace   //创建日志文件
sysuse auto, clear   //导入数据包
//查看price的概要
sum price
//查看mpg的概要
codebook mpg

ci mean rep78    //查看置信区间

corr weight length    //查看变量之间的相关性

pwcorr price headroom mpg displacement

3、Stata中输出表结果到Excel中

安装tab2xl命令、安装tab2docx

ssc install http://www.stata.com/users/kcrow/tab2xl, replace
ssc install http://www.stata.com/users/kcrow/tab2docx

Tab2xl允许权重,if, in, 格式化单元格和双向表。一旦安装,您可以输入

sysuse auto, clear
tab2xl rep78 foreign in 1/50 [fweight-mpg] using testfile, col(1) row(1)

你可能感兴趣的:(2、Stata入门---如何保证分析的可重复性)