随笔分类 - stata
摘要:STATA 代码段驻留内存,方便调用 program counta use ceshi1,clear #delimit ; merge 1:1 id using ceshi2,update replace ; #delimit cr list end //运行上述代码后,则以后可输入counta来代
阅读全文
摘要:use ceshi1,clear list // // + + // | id ks2019 ks2020 ks2021 ks2022 ks2023 ab | // | | // 1. | 1 1 0 1 2 0 1 | // 2. | 2 2 0 2 3 2 . | // 3. | 3 3 0 3
阅读全文
摘要:import pyreadstat as pyreadstat dataframe, meta = pyreadstat.read_dta("1.dta") #stata变量标签: print(meta.column_labels) #stata变量名: print(meta.column_name
阅读全文
摘要://手工输入数据保存为mb1.dta input id ks2020 ks2021 ks2022 ks2023 1 1 2 3 4 2 4 1 3 2 3 7 0 3 0 4 10 -1 3 -2 5 13 -2 3 -4 6 16 -3 3 -6 7 19 -4 3 -8 8 22 -5 3 -1
阅读全文
摘要:import pandas as pd from sqlalchemy import create_engine # read in the Statal file df = pd.read_stata('1.dta') # create a connection to the MySQL data
阅读全文
摘要:. export excel using "D:\statashu\221.xls", firstrow(variables) nolabel //将当前表导出为xls,第一行作为标题,没有值标签 //导入xls,第一行作为变量名 import excel "D:\statashu\221.xls"
阅读全文
摘要:* 加载一个Stata数据集 sysuse auto * 在Stata中执行Python代码 python: import pandas as pd import pymysql import stata_setup stata_setup.config("c:\python37\python.ex
阅读全文
摘要://stata调用python,引用py文件中的函数 //stata中设置python路径 set python_exec d:\python37\python.exe //stata中调用python python //引入函数 from myfunction1 import add_number
阅读全文
摘要:webuse dollhill2, clear gen n = _n gen N = _N 如果想要统计各个不同的年龄段中共多少人吸烟: by age (smokes), sort: generate wgta=pyears[_N] . by age (smokes), sort: generate
阅读全文
摘要:clear input ID year var1 var2 var3 1 2006 34 45 65 1 2007 45 43 41 1 2007 3 56 59 1 2008 39 54 76 1 2009 41 57 68 end save "data00.dta", replace use "
阅读全文
摘要:stata 统计每行各个变量共有几个是缺失值: //增加新变量miss,统计当前行观测值有几个缺失值 egen miss=rowmiss(_all)
阅读全文
摘要:webuse hbp2, clear //不显示值标签,只显示实际保存值 tab race ,nolabel // // Race | Freq. Percent Cum. // + // 1 | 196 17.41 17.41 // 2 | 773 68.65 86.06 // 3 | 157 1
阅读全文
摘要:. bysort rep78: gen ab=_n . order ab,after(rep78) . bysort rep78: gen abb=sum(rep78) . order abb,after(rep78)
阅读全文
摘要://1.显示stata的系统路径 . sysdir STATA: D:\Stata17\ //stata软件的安装位置 BASE: D:\Stata17\ado\base\ //stata官方的命令及说明帮助文件 SITE: D:\Stata17\ado\site\ PLUS: C:\Users\z
阅读全文
摘要:use cfps2014adult_201906, clear label list brow if fid10 8 // inlist(z,a,b,.….)语法描述:当z满足a,b,….中的任何一个,则返回值为1,否则为0。所有参数必须是实数或者字符型数据, // 其中数值型参数的个数需要在2~2
阅读全文
摘要:https://www.lianxh.cn/news/2916ae8363459.html https://www.xiaohongshu.com/explore/62fc6f8c00000000140361fa use cfps2018famecon_202101,clear keep fid18
阅读全文
摘要:.edit //编辑查看当前数据 右击任意一数据,选择"数据"--"值标签"--可选择:从值标签赋值 附加值标签给变量 隐藏所有值标签等相关操作 //从值标签赋值:将13条观测值的tb1m_a_c9 利用值标签修改为-2 . replace tb1m_a_c9 = -2 in 13 . replac
阅读全文
摘要://字母小写转大写 . disp strupper("mybook") MYBOOK . disp strupper("da") DA //字母大写转小写 . disp strlower("ASDF") asdf //每个单词首字母大写 . disp strproper("this is a boo
阅读全文
摘要://stritrim(s1)将s1中的多个连续空格缩减为一个空格 . disp stritrim("good 123") good 123 //strltrim(s1)将s1中左侧的空格删除 . disp strltrim(" good 123") good 123 //strltrim(s1)将s
阅读全文
摘要:*split字符分隔 *1,2,3 -- > 1 2 3 clear //清内存 set obs 5 //设置5个样本 gen v1 = "1 2 3" //建立新变量,v1,其值都是"1 2 3" split v1,gen(a) //分隔v1,建立以a开头后面是分隔字符的变量名,空格是默认分隔符
阅读全文

浙公网安备 33010602011771号