随笔分类 - stata
摘要://清除内存 clear //设置5个样本 set obs 5 //增加变量v1,都是this is the day gen v1 = "this is the my is day" //增加新变量,v1_replace,其值是替换v1中的第一个is为X gen v1_replace = subin
阅读全文
摘要:local sj=subinstr(subinstr("`c(current_time)'",":","",.)," ","",.) local wjma="`sj'" set seed `wjma' clear local shu= int(100*runiform() ) // local xm
阅读全文
摘要:local sj=subinstr(subinstr("`c(current_time)'",":","",.)," ","",.) local wjma="`sj'" set seed `wjma' clear local shu= int(100*runiform() ) // local xm
阅读全文
摘要:// plural(n,s) // // 用法:为字符串加s变为复数,当n的取值不是+/-1时,就在s后添加后缀"s";当n的取值是+/-1时,就在s后不加后缀"s" //n为1,不加s . disp plural(1,"banana") banana //n为2,加s . disp plural(
阅读全文
摘要:indexnot函数分析与详例解析 //indexnot(s1,s2)以单个字符判断为依据,结果是在s1中的位置表示; //indexnot(s1,s2) 返回s1中第一个在s2中找不到的字母的位置,若s1所有的字母在s2中均可以找到,则返回0 //字符a在第二个串中包含,而b不包含,b的位置是2,
阅读全文
摘要:sysuse auto, clear tab mpg,m recode mpg (10/19=.) (20/29=2) (30/39=6) (40/49=10) tab mpg,m
阅读全文
摘要:webuse auto, clear //1.删除mpg重复的数据,只保留一行,结果每行的mpg值不相同 duplicates drop mpg,force //方法2: bys mpg:gen filter=_n keep if filter==1
阅读全文
摘要:webuse auto, clear brow isid price isid mpg sample 10 //修改变量名price的标签 label variable price "my price" label variable foreign "Car originz" //删除指定变量tur
阅读全文
摘要://替换所有空格 //下面语句结果为4 disp length(subinstr(" 123 3 "," ","",.)) //itrim(s) 将字符间多于一个空格缩减为一个空格,对首尾空格不起作用 disp length(itrim(" 123 3 ")) 替换变量中的中文符号 replace
阅读全文
摘要://截取make值的第5 6 7三个字符作为新变量avvv的值 gen avvv=substr(make,5,3) order avvv ,after(make) //substr(s,n1,n2) 用法:s为需要提取的字符串,n1表示提取的起始位置,n2表示要提取的字符字符串的长度。如果n1 <
阅读全文
摘要:STATA:字符型 数值型变量转换 //real()将字符转为数字 gen a6=price+real("1") //将变量a6的类型设置为int(原来浮点型) recast int a6 //将变量a6的类型由int转为str tostring a6,replace //将变量a6的类型由str转
阅读全文
摘要://word函数是以空格为界 //word(s,n) 取得字符串s的第n个单词 // make a1 a2 //make:AMC Concord Concord AMC order a1 a2,after(make) //返回变量make的第2个单词 gen a3=word(make,2) //返回
阅读全文
摘要:STATA每次打开自动记录单独的日志,不覆盖,便于分析错误原因 //将当前相关代码复制到stata安装目录下的profile.do文件中 //每次打开stata自动保存日志不丢失,不覆盖,以打开stata时日期时间为日志文件名,便于分析错误找原因 local wjm=subinstr(subinst
阅读全文
摘要:cond(ifc, a, b):条件 ifc 为真时,返回 a, 否则返回 b inrange(x, a, b):如果变量x取值在a 至b之间时,该变量取 1,反之取 0 inlist(x, a, b, ...):如果变量x取值包含a,b,...等取值时,该变量取 1,反之取 0 clip(x, a
阅读全文
摘要:length("asdf") //检测字符串长度 //*命令 subinstr(S1,S2,S3,n),n表示迭代的次数,S1是变量,S2是需要替代的变量,S3是新替换的变量。如果n是.代表所有的都换*/ //reverse()字符串逆顺 local wjm="`c(current_time)'`c
阅读全文
摘要:display "`c(current_time)' `c(current_date)'" local wjm="`c(current_time)'`c(current_date)'" wjm=subintstr(local wjm,":","",2) disp local wjm
阅读全文
摘要://求余数:mod(_n,2)==0 use auto1, clear replace price=price+10 if mod(_n,2)==0 abs(x) 绝对值 abs(-9)=9 comb(n,k) 从n中取k个的组合 comb(10,2)=45 exp(x) 指数 exp(0)=1 f
阅读全文
摘要:webuse auto, clear //写两个命令,先排序,再建立新变量 //根据foreign排序,新生新变量,其值是不同的foreign分别从1开始计数 sort foreign by foreign:gen filter=_n //上面两个命令写成一个命令,功能相同 bys foreign,
阅读全文
摘要:import pandas as pd from pandas.io.stata import StataReader, StataWriter file="cfps2020famconf_202301.dta" stata_data = StataReader(file, convert_cate
阅读全文
摘要:import pandas as pd data = pd.read_stata('cfps2020famconf_202301.dta') data.to_stata('output_file.dta') data.to_stata('output_file.dta', version=12) #
阅读全文

浙公网安备 33010602011771号