Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error with -fre- (SSC) when using strings with Chinese (traditional) text

    When using -fre- from Ben Jann (on SSC) with string variables containing Chinese (traditional) text, the Mata error message "3301 subscript invalid" appears. -set trace- shows that this happens with -mata: fre_display_or_export()-. However, -tab1- has no problems with these data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str254(aftschs pjdiscrs vcybures)
    "再說吧" "很多人" "-66"                  
    "半工半讀" "看起來經濟狀況不佳的人" "我不知道"         
    "進大學或找份工作" "在西方某些國家,凡不是白種人皆有可能,但在大部分國家,窮人被鄙視" "個性"               
    "我要成為海賊王" "外星人" "-66"                  
    "國中畢業前,找到興趣,會去高職學習,沒找到,則是選擇繼續升學,準備進大學。" "長的醜,黑人,黃種人" "遊戲玩的好不好"
    "出國留學" "種族不同 國籍不同 曾經有前科的人" "我的個性"         
    "出國留學" "身障者" "-66"
    "-99" "國際移工" "因為我在課堂上表現得比他們好、他們喜歡的男生和我說話"                  
    end
    label var aftschs "other (write in):"
    label var pjdiscrs "不是的,有些人沒有被平等對待。哪些人? %s (請註明)"
    label var vcybures "其他(請說明):"
    
    tab1 aftschs pjdiscrs vcybures
    cap noi: fre aftschs
    cap noi: fre pjdiscrs
    cap noi: fre vcybures
    The output shows:
    Code:
    . tab1 aftschs pjdiscrs vcybures
    
    -> tabulation of aftschs  
    
                          other (write in): |      Freq.     Percent        Cum.
    ----------------------------------------+-----------------------------------
                                        -99 |          1       12.50       12.50
                                      再說吧 |          1       12.50       25.00
                                    出國留學 |          2       25.00       50.00
                                    半工半讀 |          1       12.50       62.50
           國中畢業前,找到興趣,會去高職學習,.. |          1       12.50       75.00
                               我要成為海賊王 |          1       12.50       87.50
                              進大學或找份工作 |          1       12.50      100.00
    ----------------------------------------+-----------------------------------
                                      Total |          8      100.00
    
    -> tabulation of pjdiscrs  
    
                     不是的,有些人沒有被平等對 |
                      待。哪些人? %s (請註明) |      Freq.     Percent        Cum.
    ----------------------------------------+-----------------------------------
                                    國際移工 |          1       12.50       12.50
           在西方某些國家,凡不是白種人皆有可能.. |          1       12.50       25.00
                                      外星人 |          1       12.50       37.50
                                      很多人 |          1       12.50       50.00
                         看起來經濟狀況不佳的人 |          1       12.50       62.50
                種族不同 國籍不同 曾經有前科的人 |          1       12.50       75.00
                                      身障者 |          1       12.50       87.50
                          長的醜,黑人,黃種人 |          1       12.50      100.00
    ----------------------------------------+-----------------------------------
                                      Total |          8      100.00
    
    -> tabulation of vcybures  
    
                               其他(請說明): |      Freq.     Percent        Cum.
    ----------------------------------------+-----------------------------------
                                        -66 |          3       37.50       37.50
                                        個性 |          1       12.50       50.00
           因為我在課堂上表現得比他們好、他們喜.. |          1       12.50       62.50
                                    我不知道 |          1       12.50       75.00
                                    我的個性 |          1       12.50       87.50
                               遊戲玩的好不好 |          1       12.50      100.00
    ----------------------------------------+-----------------------------------
                                      Total |          8      100.00
    
    . cap noi: fre aftschs
     fre_display_or_export():  3301  subscript invalid
                     <istmt>:     -  function returned error
    
    . cap noi: fre pjdiscrs
     fre_display_or_export():  3301  subscript invalid
                     <istmt>:     -  function returned error
    
    . cap noi: fre vcybures
     fre_display_or_export():  3301  subscript invalid
                     <istmt>:     -  function returned error
    Is there anyone who could come up with a solution to this problem?

  • #2
    fre has been written long before Stata supported unicode characters, I guess the problem is caused by Chinese characters that occupy more than two display columns, so that character counts get mixed up. I'll try to fix this but cannot make any promises.
    ben

    Comment


    • #3
      It seems that I already fixed this back in 2015 (!) but then sent a wrong file to Kit Baum. I now forwarded the correct file to Kit so that he can release an update on SSC. I now also published the package on GitHub (https://github.com/benjann/fre) so you can also type

      Code:
      . net install fre, replace from(https://raw.githubusercontent.com/benjann/fre/main/)
      to obtain the fixed version. Please let me know if the update does not fix the problem (type discard of restart Stata after installing the update to make sure the old version is no longer in working memory).
      ben

      Comment


      • #4
        Thanks -- in version 1.2.5 (01jun2015) (GitHub) the problem is solved [not in version 1.2.5 (30may2015)] .

        Comment


        • #5
          Yes, "version 1.2.5 (30may2015)" is the wrong file I accidentally sent to Kit back in 2015. The corrected version should become available from SSC within the next days.

          Comment

          Working...
          X