Announcement

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

  • Box plot - Am sure it's easy and I can't spot it

    Hello there, i am trying out some stata exercise on my personal subscription and unlike previous posts I have dataex insalled on my STATA.

    I am trying to create a boxplot for variable: Fitbit

    Stata produces the boxplot but with the wrong Y axis - ID no rather than the Fitbit data which ranges from 623 - 750.
    What am I doing wrong please?
    Code used:

    graph box Fitbit

    Box plot produced:

    Click image for larger version

Name:	Screenshot 2022-06-17 at 12.14.55.png
Views:	2
Size:	69.9 KB
ID:	1669654

    Dataex:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float ID long(Fitbit Treadmill)
    1  4  4
    2  7  7
    3 16 16
    4 12 17
    5 17 11
    end
    label values Fitbit Fitbit
    label def Fitbit 4 "645", modify
    label def Fitbit 7 "658", modify
    label def Fitbit 12 "691", modify
    label def Fitbit 16 "717", modify
    label def Fitbit 17 "730", modify
    label values Treadmill Treadmill
    label def Treadmill 4 "602", modify
    label def Treadmill 7 "636", modify
    label def Treadmill 11 "654", modify
    label def Treadmill 16 "692", modify
    label def Treadmill 17 "709", modify
    Attached Files

  • #2
    Hi Martin
    Stata is doing the right thing. Is creating the box plot based on the values of FITBIT (4-17 in your example)
    What seems you want is to plot the labels 645-709.
    Thus you need to make those labels into values.
    HTH
    F

    Comment


    • #3
      Martin:
      Code:
      . label drop Fitbit
      
      . graph box Fitbit
      should give back what you want.
      The issue is that you inputted -label- instead than values.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Two guesses here and I am going to go with your needing to make your labels into values.

        Code:
        clear
        input float ID long(Fitbit Treadmill)
        1  4  4
        2  7  7
        3 16 16
        4 12 17
        5 17 11
        end
        label values Fitbit Fitbit
        label def Fitbit 4 "645", modify
        label def Fitbit 7 "658", modify
        label def Fitbit 12 "691", modify
        label def Fitbit 16 "717", modify
        label def Fitbit 17 "730", modify
        label values Treadmill Treadmill
        label def Treadmill 4 "602", modify
        label def Treadmill 7 "636", modify
        label def Treadmill 11 "654", modify
        label def Treadmill 16 "692", modify
        label def Treadmill 17 "709", modify
        
        foreach v in Fitbit Treadmill {
            decode `v', gen(`v'2)
            destring `v'2, replace
            drop `v' 
            rename `v'2 `v '
        }


        Comment


        • #5
          thanks I dropped the labels as Carlo said and it worked.

          Just to let you know, when I tried to destring it - from blue it came to red which of course wouldn't work. Not sure if I misunderstood you Nick.
          Dropping the labels worked.

          Comment


          • #6
            Martin:
            unexpectedly (tongue in cheek, obviously ) Nick Cox 's code works like a charm.
            I also apologize for my atrocious mixing up "rather than" with "instead of" in my previous post, that created the linguistic ircocervo (https://en.wiktionary.org/wiki/ircocervo) "instead than".
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Dropping the labels should leave you with numbers like 4 and 17 -- precisely what you complained about in #1/

              Comment

              Working...
              X