2014-11-05 66 views
1

因此,我在Stata中有一個名爲「程序描述」的變量,該變量具有非常相似的觀察結果,儘管觀察結果沒有遵循任何模式。我的目標是清理變量,以便非常相似的觀察值具有相同的名稱。清理具有高度相似觀察結果的變量

這裏是什麼樣的變量看起來像一個例子:

Variable Name 

phys ed 
physical education 
phys ed k-12 
learning disabilities 
learn dis 
learn disable 

因此,我想前三,只是被稱爲「PHY的ED」(或某些衍生物)和過去的三隻是被稱爲「學習障礙」

我一直在使用函數strpos()來取代包含某些短語的觀察值,但因爲變量有100k個觀察值和很多不同的名字,這需要一段時間。

+0

這已經出現了幾次www.statalist.com。我會尋找那裏提供的答案,因爲已經提出了很多解決方案。不幸的是,我目前無法提供任何鏈接。 – 2014-11-05 22:11:34

+0

我到處尋找信息,並沒有發現任何有用的東西,所以如果你找到任何鏈接,請告訴我。 – Pcarlitz 2014-11-06 03:16:45

+0

http://www.stata.com/statalist/archive/2013-11/msg01209.html和http://www.stata.com/statalist/archive/2012-03/msg01135.html和http:// www .stata.com/statalist/archive/2004-02/msg00246.html和http://www.statalist.org/forums/forum/general-stata-discussion/general/754-repeated-names-in-a-string - 可變 - 但有一些錯別字 - 如何糾正,更一般地說:https://www.google.com/search?q=statalist+%2B+string+match&gws_rd=ssl#q=statalist+%2B+模糊+字符串+ – 2014-11-06 03:22:47

回答

3

您可以使用SSC的strgroup,但它不太可能讓您一路暢通。例如,這似乎工作:

. strgroup string , gen(group) threshold(.7) normalize(longer) 

. list, clean noobs 

        string group 
        phys ed  1 
     physical education  1 
      phys ed k-12  1 
    learning disabilities  2 
       learn dis  2 
      learn disable  2 

但是,「物理」將被映射到組1與這些設置。另外請注意,這個命令是區分大小寫的,所以最好先寫大寫/小寫。閾值實際上是一種調整參數。

我也有一些運氣與Google/Open Refine這些問題。這稱爲和解。通過所有這些方法,一些標準化工作將取得很大進展。

+0

我一直在尋找這麼久才找到這樣的命令......謝謝! – Pcarlitz 2014-11-06 03:12:11

+0

@Pcarlitz如果這對你有用,請選擇答案。 – 2014-11-06 19:52:15