摘要: #include <stdio.h> //求任意两个数的最小公倍数 main() { int a,b,i; scanf("%d%d",&a,&b); for(i=a;i<=a*b;i++) if(i%a==0 && i%b==0) { printf("%d %d的最小公倍数为:%d\n",a,b,i 阅读全文
posted @ 2023-03-05 20:35 myrj 阅读(155) 评论(0) 推荐(0) 编辑
摘要: //替换所有空格 //下面语句结果为4 disp length(subinstr(" 123 3 "," ","",.)) //itrim(s) 将字符间多于一个空格缩减为一个空格,对首尾空格不起作用 disp length(itrim(" 123 3 ")) 替换变量中的中文符号 replace 阅读全文
posted @ 2023-03-05 19:46 myrj 阅读(1824) 评论(0) 推荐(0) 编辑
摘要: //截取make值的第5 6 7三个字符作为新变量avvv的值 gen avvv=substr(make,5,3) order avvv ,after(make) //substr(s,n1,n2) 用法:s为需要提取的字符串,n1表示提取的起始位置,n2表示要提取的字符字符串的长度。如果n1 < 阅读全文
posted @ 2023-03-05 19:06 myrj 阅读(2659) 评论(0) 推荐(0) 编辑
摘要: STATA:字符型 数值型变量转换 //real()将字符转为数字 gen a6=price+real("1") //将变量a6的类型设置为int(原来浮点型) recast int a6 //将变量a6的类型由int转为str tostring a6,replace //将变量a6的类型由str转 阅读全文
posted @ 2023-03-05 18:47 myrj 阅读(6064) 评论(0) 推荐(0) 编辑
摘要: //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) //返回 阅读全文
posted @ 2023-03-05 15:26 myrj 阅读(79) 评论(0) 推荐(0) 编辑
摘要: STATA每次打开自动记录单独的日志,不覆盖,便于分析错误原因 //将当前相关代码复制到stata安装目录下的profile.do文件中 //每次打开stata自动保存日志不丢失,不覆盖,以打开stata时日期时间为日志文件名,便于分析错误找原因 local wjm=subinstr(subinst 阅读全文
posted @ 2023-03-05 11:12 myrj 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2023-03-05 10:50 myrj 阅读(248) 评论(0) 推荐(0) 编辑
摘要: length("asdf") //检测字符串长度 //*命令 subinstr(S1,S2,S3,n),n表示迭代的次数,S1是变量,S2是需要替代的变量,S3是新替换的变量。如果n是.代表所有的都换*/ //reverse()字符串逆顺 local wjm="`c(current_time)'`c 阅读全文
posted @ 2023-03-05 09:23 myrj 阅读(186) 评论(0) 推荐(0) 编辑
摘要: display "`c(current_time)' `c(current_date)'" local wjm="`c(current_time)'`c(current_date)'" wjm=subintstr(local wjm,":","",2) disp local wjm 阅读全文
posted @ 2023-03-05 06:21 myrj 阅读(173) 评论(0) 推荐(0) 编辑
摘要: //求余数: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 阅读全文
posted @ 2023-03-05 05:20 myrj 阅读(262) 评论(0) 推荐(0) 编辑
摘要: webuse auto, clear //写两个命令,先排序,再建立新变量 //根据foreign排序,新生新变量,其值是不同的foreign分别从1开始计数 sort foreign by foreign:gen filter=_n //上面两个命令写成一个命令,功能相同 bys foreign, 阅读全文
posted @ 2023-03-05 05:15 myrj 阅读(41) 评论(0) 推荐(0) 编辑