最新Stata函数大全.docx
《最新Stata函数大全.docx》由会员分享,可在线阅读,更多相关《最新Stata函数大全.docx(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精品资料Stata函数大全.Stata函数大全一、数值型函数abs(x) 绝对值 abs(-9)=9comb(n,k) 从n中取k个的组合 comb(10,2)=45exp(x) 指数 exp(0)=1fill() 自动填充数据int(x) 取整 int(5.6) = 5, int(-5.2) = -5.ln(x) 对数 ln(1)=0log10(x) 以10为底的对数 log10(1000)=3mod(x,y) = x - y*int(x/y) mod(9,2)=1round(x) 四舍五入 round(5.6)=6sqrt(x) 开方 sqrt(16)=4sum(x) 求和随机函数unif
2、orm() 均匀分布随机数invnormal(uniform() 标准正态分布随机数字符函数real(s) 字符型转化为数值型string(n) 数值型转化为字符型substr(s,n1,n2) 从S的第n1个字符开始,截取n2个字符 Substr(“this”,2,2)=isword(s,n) 返回s的第n个字符 Work(“this”,3)=ichar(n) 返回字符的ASCII码indexnot(s1,s2) 返回s1中第一个在s2中找不到的字母的位置,若s1所有的字母在s2中均可以找到,则返回0例如:indexnot(12disxl,2fsd1)=4 indexnot(12disxl,
3、2fsd1ixs)=7indexnot(12disxl,2fsd1lixs)=0itrim(s) 将字符间多于一个空格缩减为一个空格例如:itrim(hello there) = hello therelength(s) 返回字符串s的长度例如:length(ab) = 2lower(s) 将s中的字母变为xiaoxie例如:lower(THIS) = thisltrim(s) 将字符串s中首字母之前的空格去掉例如:ltrim( this) = thisplural(n,s) or plural(n,s1,s2)如果n!=+/-1, plural(n,s)就是将s加到s后。如果s2前有+,表示
4、将s2加到s1后,如果s2前为-,则返回s1中去掉s2 字符串后剩下的字符串。如果s2前既没有+也没有-,则plural(n,s1,s2)=s2.例如:plural(1, horse) = horseplural(2, horse) = horsesplural(2, glass, +es) = glassesplural(1, mouse, mice) = mouseplural(2, mouse, mice) = miceplural(2, abcdefg, -efg) = abcdproper(s) 将首字母大写,而且将紧接着非字母字符后的字母大写,其他的字母小写例如:proper(mR
5、. joHn a. sMitH) = Mr. John A. Smithproper(jack oreilly) = Jack OReillyproper(2-cents worth) = 2-CentS Worthreal(s) 将s字符串转化为数字后返回,或返回“.”例如:real(5.2)+1 = 6.2real(hello) = .reverse(s) 将字符串颠倒过来例如:reverse(hello) = ollehrtrim(s) 去掉字符串末尾的空格例如:rtrim(this ) =this.string(n) 将数字n转化为字符串例如: string(4)+F = 4Fstri
6、ng(1234567) = 1234567string(12345678) = 1.23e+07string(.) = .string(n,s) 将数字n转化为字符串例如:string(4,%9.2f) = 4.00string(123456789,%11.0g) = 123456789string(123456789,%13.0gc = 123,456,789string(0,%td) = 01jan1960string(225,%tq) = 2016q2string(225,not a format) = strmatch(s1,s2) s2与s1的形式相同则返回1,否则返回0例如:str
7、match(17.4,1?4)=1 在s2中?代表此处有一个字符,*表示0或更多的字符 strpos(s1,s2) s2在s1中第一次找到的位置,否则为0例如:strpos(this,is) = 3strpos(this,it) = 0subinstr(s1,s2,s3,n) 返回s1,将s1中第n次出现s2时的s2替换成s3 ,若n为”.”,则将所有s1中的s2字符串替换成s3例如:subinstr(this is this,is,X,1) = thX is thissubinstr(this is this,is,X,2) = thX X thissubinstr(this is this
8、,is,X,.) = thX X thXsubstr(s,n1,n2) 返回s1的子集,从s1中第n1个字符开始抽取,抽n2个字符例如: substr(abcdef,2,3) = bcdsubstr(abcdef,-3,2) = desubstr(abcdef,2,.) = bcdefsubstr(abcdef,-3,.) = defsubstr(abcdef,2,0) = substr(abcdef,15,2) = trim(s) 将字符串s的首字母之前和末尾的空格去掉例如:trim( this ) =thisupper(s) 将字符串s中的字母变为大写例如:upper(this) =THI
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新 Stata 函数 大全
限制150内