全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1985 4
2014-08-14
我现在有时间变量fpeyq,是写年份和季度的,比如2001_1, 是2001年第一季度。
现在希望新建一个变量year, 把季度去掉,也就是说只留下2001, 2002, 2003这样的信息。
请问怎么写命令,谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-8-14 15:42:07
Title
[M5]
substr( ) — Extract substring
Syntax
string matrix substr(string matrix s, real matrix b, real matrix l)
string matrix substr(string matrix s, real matrix b)
Description
substr(s, b, l) returns the substring of s starting at position b and continuing for a length of l,
where
1. b specifies the starting position; the first character of the string is b = 1.
2. b > 0 is interpreted as distance from the start of the string; b = 2 means starting at the
second character.
3. b < 0 is interpreted as distance from the end of string; b = &#1048576;1 means starting at the last
character; b = &#1048576;2 means starting at the second from the last character.4. l specifies the length; l = 2 means for two characters.
5. l < 0 is treated the same as l = 0: no characters are copied.
6. l  . is interpreted to mean to the end of the string.
substr(s, b) is equivalent to substr(s, b, .) for strings that do not contain binary 0. If there
is a binary 0 to the right of b, the substring from b up to but not including the binary 0 is returned.
When arguments are not scalar, substr() returns element-by-element results.
Conformability
substr(s, b, l):
s: r1  c1
b: r2  c2
l: r3  c3; s, b, and l r-conformable
result: max(r1; r2; r3)  max(c1; c2; c3)
substr(s, b):
s: r1  c1
b: r2  c2; s and b r-conformable
result: max(r1; r2)  max(c1; c2)
Diagnostics

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-8-15 08:20:28
crystal8832 发表于 2014-8-14 15:42
Title
[M5]
substr( ) — Extract substring
版主版主。。。我看不懂哎。。。你这是STATA嘛?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-8-15 08:39:03
lindawu204 发表于 2014-8-15 08:20
版主版主。。。我看不懂哎。。。你这是STATA嘛?
我给你发的是Stata的 文档里的。
help substr(s,b,l)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-8-20 09:40:24
gen year=real(substr(fpeyq,1,4))
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群