Announcement

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

  • Correctly using Tabulate and Histogram

    Hi,

    I'm working with a client base (6000 IDs) in panel (t=24 months).

    They're classified in Gold/Silver/Bronze (string), which may or may not change in time t:
    ID Class
    1 Gold
    2 Silver
    3 Bronze
    4 Bronze
    5 Gold
    6 Silver
    I'd like to tabulate this variable so Bronze =1, Silver=2, Gold=3... but when I use tabulate it's seems to be random. Can i "force" it somehow?

    Then I'm having a hard time any graphical function (hist, xtline)... I'm probably missing an argument for the functions to work properly, but I don't know which and where it goes. When I don't get an error message, stata just keeps processing, most likely because it's trying to deal with too many data that (like plotting every ID). Could someone please point me towards the right direction this issue?

    Thanks!

  • #2
    Domingos:
    try:
    Code:
    g Class_num=1 if Class=="Bronze"
    replace Class_num=2 if Class=="Silver"
    replace Class_num=3 if Class=="Gold"
    label define Class_num 1 "Bronze" 2 "Silver" 3 "Gold"
    label val Class_num Class_num
    tab Class_num
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Here is another way to do what Carlo is suggesting:

      Code:
      label define Class_num 1 "Bronze" 2 "Silver" 3 "Gold"
      encode Class, gen(Class_num) label(Class_num)
      tab Class_num
      On graphs: sorry, we can't tell what you are doing wrong if you don't tell us exactly what you are doing. Please study http://www.statalist.org/forums/help #12

      Code:
      histogram Class_num, discrete
      should do something.

      Comment


      • #4
        Nick Cox and Carlo Lazzaro, thanks for the help!

        Originally posted by Nick Cox View Post
        On graphs: sorry, we can't tell what you are doing wrong if you don't tell us exactly what you are doing. Please study http://www.statalist.org/forums/help #12
        Sorry, I'm at such a loss that I couldn't flesh out the doubt clearly enough.

        Consider another descriptive variable Reg (for country Region: North, South, West, East):
        ID Class Region Apples_Bought
        1 Gold N 5
        2 Silver S 4
        3 Bronze W 3
        4 Bronze W 2
        5 Gold E 1
        6 Silver N 10

        How can I see a histogram of how many individuals are there in a Class by each Region?

        How can I see a line by a descriptive variable (say, DV) instead of by ID?

        Comment


        • #5
          I'll repeat my request to study that part of the FAQ Advice cited in #3. That includes how to present a data example that people can use easily. In your case, there is no variable called DV.

          Comment

          Working...
          X