Announcement

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

  • ID variable

    Hi,
    I need to create ID variable which will assign numbers to my panel data variable "Bankname" .
    I have already run the following command:
    encode Bankname, gen(id)
    list Bankname in 1/1867

    however did not get the desired results as numbers are in an increasing order. I need to have the same number for the same banks


    Thanks for your help

    kind regards,
    Nigar

  • #2
    what happens when you issue the command tab id? Sounds like you ran encode OK, might just be your way of displaying results is off?

    Comment


    • #3
      tab id command shows the following results
      Bankname Freq. Percent Cum.
      (with their respective values)
      ...........................................

      Comment


      • #4
        does tab id have the same frequency as tab Bankname?

        Comment


        • #5
          Yes, exactly the same

          Comment


          • #6
            So, I don't understand what the problem is. You have generated id using -encode-, and it has the same frequency distribution as Bankname. What is it you want? Show us a sample of the data you started with, and then show us in that sample what you would like to get as a result.

            Comment


            • #7
              I want to get list of numbers which exactly matches the bank name. Say if Bank A appears 4 times in a dataset, I should have 4 "1"s (for example, it could 2, 3 or 4 etc) in the id column.


              Bank Name Year ID

              Bank A 1999 1
              BAnk A 2000 1
              Bank A 2001 1
              Bank A 2002 1

              Comment


              • #8
                please show us the exact commands, and the exact results. Seems like Stata is doing what you want.

                Comment


                • #9
                  If your BankA spelled 4 times differently, encode will generate 4 different codes.

                  Consider the following example:

                  Code:
                  clear
                  input str10 name
                  "Bank A"
                  "BankA"
                  "bankA"
                  "banka"
                  end
                  
                  encode name, generate(code)
                  list, nol
                  Produces:

                  Code:
                       +---------------+
                       |   name   code |
                       |---------------|
                    1. | Bank A      1 |
                    2. |  BankA      2 |
                    3. |  bankA      3 |
                    4. |  banka      4 |
                       +---------------+
                  It is not very clear what you want to do and what problem you have, We understand you work with data you can't share, but work out a simple example from start to finish. Make sure you explain everything relevant and remove everything non-relevant. How is the year important in the example you show?

                  http://translate.google.com translates into English from most common languages. Language should not be a barrier to ask a question in this forum, but poorly translated question can confuse a lot. From what you wrote at 23:56 I could equally suggest Stata's duplicates and collapse commands, as well as Roger Newson's sencode, but the symptoms you describe agree with inconsistent spelling of banks' names in multiple years. All three commands are useful so check them out.

                  Best, Sergiy Radyakin

                  Comment


                  • #10
                    Thanks to all for replies

                    Below I attached the extract from results. The command is:
                    encode Bankname, gen(id)
                    list Bankname in 1/1867

                    Comment


                    • #11
                      Nigar: Sorry, but your photo is illegible, at least to me. In any case, a listing of 1867 observations will not fit on to most monitors.

                      Please re-read the FAQ Advice here on posting readable results (Section 12) and also using full real names (Section 6). http://www.statalist.org/forums/help

                      Comment


                      • #12
                        Click image for larger version

Name:	Untitled.png
Views:	2
Size:	9.4 KB
ID:	137707

                        Sorry for that.
                        I have uploaded new file as You requested

                        Many thanks

                        Comment


                        • #13
                          So I still don't understand what you want. The snapshot of the data you show has four entries with identical Bankname, and the id variable appears to be identical in those four observations as well. That seems to be correct. In what way is that not what you want? What do you need to see under id?

                          Comment


                          • #14
                            What I want to see under id is the numbers that will be assigned to Bank names. Identical numbers for the same banks names. Does Stata recognize the dataset constructed in that way as panel data? I mean after running commands like:
                            sort $id $years
                            xtset $id $years

                            So, if it is ok, then I think I can proceed with such dataset, can"t I?


                            Thank you

                            Comment


                            • #15
                              If you want to see the correspondence between bank names and numbers you can either do -label list id-. If you want to browse the data set and have the id number show up as a number, do -browse, nolabel-.

                              In any case, the variable -id-, created in the way you described earlier, is a numeric variable (which you can confirm with -describe id-), and will work just fine with xtset.

                              By the way, why are you putting $ characters in front of the variable names in the -sort- and -xtset- commands in your last post?

                              Comment

                              Working...
                              X