楼主: 回忆与我
45748 20

[编程问题求助] 关于stata的strmatch 和regexm [推广有奖]

  • 1关注
  • 0粉丝

已卖:55份资源

学术权威

30%

还不是VIP/贵宾

-

威望
0
论坛币
1017 个
通用积分
109.7687
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
234050 点
帖子
2774
精华
0
在线时间
1636 小时
注册时间
2012-12-14
最后登录
2025-12-28

楼主
回忆与我 学生认证  发表于 2016-11-23 22:21:22 |AI写论文
10论坛币
想筛选字符串里是否含有某一个词语,查到可以用strmatch 和regexm方法,但是两个在我的stata里都不能用,显示的是strmatch not found 或者 regexm not found。
我试了语句 keep if strmatch (name, "*科技*") 以及keep if strmatch (name, "*科技*")==1, 都不行。
如果直接输入 strmatch (name, "*科技*"), 就会显示unrecognized command:  strmatch。regexm函数也一样。
这两个函数,我都能help 到。我想是没有安装,但是我用ssc install也装不了。是不是我没有相关的文件呢?

stata菜鸟希望大神帮忙。

最佳答案

夏目贵志 查看完整内容

keep if strmatch(name, "*科技*") 不要空格
关键词:Stata Match ATCH tata ATC stata strmatch regexm
Be a magic

沙发
夏目贵志 发表于 2016-11-23 22:21:23
keep if strmatch(name, "*科技*")
不要空格
已有 1 人评分经验 论坛币 收起 理由
葫芦娃大王 + 10 + 10 精彩帖子

总评分: 经验 + 10  论坛币 + 10   查看全部评分

藤椅
黃河泉 在职认证  发表于 2016-11-24 08:08:11
我试过是可以的
  1. clear
  2. input str18 name
  3. 阿猫公司
  4. 阿狗科技公司
  5. 阿猫科技公司
  6. 阿狗公司
  7. end

  8. gen d = strmatch(name,"*科技*")

  9. . list

  10.      +------------------+
  11.      |         name   d |
  12.      |------------------|
  13.   1. |     阿猫公司   0 |
  14.   2. | 阿狗科技公司   1 |
  15.   3. | 阿猫科技公司   1 |
  16.   4. |     阿狗公司   0 |
  17.      +------------------+
复制代码
已有 1 人评分经验 论坛币 收起 理由
葫芦娃大王 + 10 + 10 精彩帖子

总评分: 经验 + 10  论坛币 + 10   查看全部评分

板凳
回忆与我 学生认证  发表于 2016-11-24 09:53:36
夏目贵志 发表于 2016-11-23 22:21
keep if strmatch(name, "*科技*")
不要空格
原来这么简单,我打了空格都没有意识到。谢谢!

报纸
回忆与我 学生认证  发表于 2016-11-24 09:54:30
黃河泉 发表于 2016-11-24 08:08
我试过是可以的
楼上的同学给我答案啦,我多敲了一个空格,所以stata就不认为是函数了。现在我也可以了,谢谢!
已有 1 人评分经验 收起 理由
葫芦娃大王 + 10 精彩帖子

总评分: 经验 + 10   查看全部评分

地板
机智的小球球IU 学生认证  发表于 2018-5-23 20:17:46
黃河泉 发表于 2016-11-24 08:08
我试过是可以的
----------------------- copy starting from the next line -----------------------
  1. * Example generated by -dataex-. To install: ssc install dataex
  2. clear
  3. input str46 institutionname str4 name
  4. "万科企业股份有限公司"         "万科"
  5. "深圳世纪星源股份有限公司"     "深圳"
  6. "深圳市振业(集团)股份有限公司" "振业"
  7. "深圳市全新好股份有限公司"     "全新"
  8. end
复制代码
------------------ copy up to and including the previous line ------------------
老师,请问想知道2个变量之间的关系——institutionname里面是否包含name,应该如何做呢?我试了如下三个code,都不可以。gen a=strmatch(institutionname,name);gen a=strmatch(institutionname,"name");gen a=strmatch(institutionname,"*name*")

7
黃河泉 在职认证  发表于 2018-5-24 07:59:48
机智的小球球IU 发表于 2018-5-23 20:17
----------------------- copy starting from the next line ----------------------------------------- ...
我看不懂你的问题?

8
黃河泉 在职认证  发表于 2018-5-24 08:08:58
机智的小球球IU 发表于 2018-5-23 20:17
----------------------- copy starting from the next line ----------------------------------------- ...
试试
  1. gen d1 = ustrregexm(institutionname, name)
  2. gen temp = strpos(institutionname, name)
  3. gen d3 = temp > 0
  4. drop temp
复制代码

9
机智的小球球IU 学生认证  发表于 2018-5-24 09:17:54
黃河泉 发表于 2018-5-24 08:08
试试
get it.谢谢老师。我回归之后d1跟d3是一样的,关键是看d1还是d3呢??

10
黃河泉 在职认证  发表于 2018-5-24 10:59:15
机智的小球球IU 发表于 2018-5-24 09:17
get it.谢谢老师。我回归之后d1跟d3是一样的,关键是看d1还是d3呢??
自己选一个 (的确,我提供两个作法)。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-29 11:56