Announcement

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

  • encode with strange number?

    Dear All, I have this data set in Stata format (dataex may not be appropriate for my purpose), encode.dta. I use
    Code:
    encode Journal_e, gen(id)
    but do not obtain `id' from 1,2, .... Please see
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str63 Journal_e long id
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accountant"                    842
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Accounting Research"           843
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural Economy"          844
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Agricultural History of China" 845
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Asia-pacific Economic Review"  846
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Auditing Research"             847
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Business & Economy"            848
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "Chemical Industry"             849
    "China Business and Market"     850
    "China Business and Market"     850
    "China Business and Market"     850
    "China Business and Market"     850
    end
    label values id id
    label def id 842 "Accountant", modify
    label def id 843 "Accounting Research", modify
    label def id 844 "Agricultural Economy", modify
    label def id 845 "Agricultural History of China", modify
    label def id 846 "Asia-pacific Economic Review", modify
    label def id 847 "Auditing Research", modify
    label def id 848 "Business & Economy", modify
    label def id 849 "Chemical Industry", modify
    label def id 850 "China Business and Market", modify
    Any suggestions? Thanks.
    Attached Files
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    I confirm that your code generates new ID from 1 to 165 in my machine . I assume that you are using unicode and it changes internal loop of encode, maybe.
    C

    Comment


    • #3
      Dear Chul, Thanks. So, suppose that you are right. What can I do now? (I used Stata 17, but the attached data file was saved using Stata 13 so that most people can try out the data.)
      Last edited by River Huang; 26 Feb 2022, 21:21.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        Other gurus would answer it if it is really a Unicode issue. I don't know much about it.
        New_ID = id - 841
        C

        Comment


        • #5
          Dear Chul, Thanks but the question has not been solved.
          Ho-Chuan (River) Huang
          Stata 17.0, MP(4)

          Comment


          • #6
            My guess is that your encode is adding to an existing set of value labels. You need a fresh start.

            Comment


            • #7
              Dear Nick, I think you are right. I encode aaa, gen(id), then after some manipulation (ssc install xtbalance), I drop `id'. Then, I do the "encode bbb, gen(id)" again. I guess this is what you said.
              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment


              • #8
                It is what the help tells you, straight off. StataCorp's words but my emphasis.

                encode creates a new variable named newvar based on the string variable varname, creating, adding to, or
                just using (as necessary) the value label newvar
                or, if specified, name.

                Comment


                • #9
                  Dear Nick, Got it and thanks.

                  Ho-Chuan (River) Huang
                  Stata 17.0, MP(4)

                  Comment

                  Working...
                  X