How do I find and replace a part of a string variable in Stata?

﹥>﹥吖頭↗ 提交于 2019-12-24 04:16:08

问题


I am working with a variable which is basically URLs. So observations include values like for example

  • www.google.com
  • https://www.google.com
  • https://yahoo.movies.com

I am trying to create a do file to import a bunch of these files into Stata and need a reliable method to remove the www. and the https:// parts from these variables over a wide range of URLs.

In Excel I can do this simply by finding https:// or www. and replacing it with nothing, how do I achieve the same in Stata?

I am working in Stata 13.1 SE on Windows 8 Pro 64 bit.


回答1:


You can use subinstr() function.

Example:

subinstr("this is this","is","X",.) = "thX X thX"


来源:https://stackoverflow.com/questions/21314192/how-do-i-find-and-replace-a-part-of-a-string-variable-in-stata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!