Announcement

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

  • graph with long string names

    Folks,

    A quick question:

    I have a de-stringed variable called "cause" that takes four values: 1,2,3, and 4, and they correspond to 1) cancer, 2) accident, 3) surgery, 4) other.

    There is another numeric variable called "death" for the number of deaths associated with the four aforementioned causes.

    When I put the command:
    Code:
    graph hbar death, over (cause)
    it produces the horizontal bar graph with numbers.

    But I would like the y-axis numeric values to indicate "cancer" "accident" "surgery" and "other.

    How would I go about doing this?

    Many thanks.



  • #2
    Code:
    graph hbar death, over(cause, relabel(1 "cancer" 2 "accident" 3 "surgery" 4 "other"))

    Comment


    • #3
      It's hard to see how destring would map "cancer" etc to 1 2 3 4. That's not what it does.

      Comment


      • #4
        Originally posted by Øyvind Snilsberg View Post
        Code:
        graph hbar death, over(cause, relabel(1 "cancer" 2 "accident" 3 "surgery" 4 "other"))
        Thanks for the help! Do you know what if I have double digit byte-type instead of double?

        I originally had 1, 2, 3, 4 as string variables. As I de-string them, they become the byte type. When I follow your code, the labels don't recognize them correctly. Is this possibly because I have them as the byte type instead of the float type?

        Please advise, thanks!

        Comment


        • #5
          Originally posted by Nick Cox View Post
          It's hard to see how destring would map "cancer" etc to 1 2 3 4. That's not what it does.
          I originally had 1, 2, 3, 4 as string variables. As I de-string them, they become the byte type. This might be the problem. I am not getting the label correctly on the y-axis of the hbar...

          Comment


          • #6
            Please give a data example. https://www.statalist.org/forums/help#stata

            #2 didn't even mention double, so I can't what you are asking in #3 any more than I can follow #1.

            (Just goes to show: "quick questions" don't usually get quick answers whenever people don't provide enough information.)

            Comment


            • #7
              #5 was posted while I was writing #6, but there is still fuzziness here. In #1 you talked about one variable and now in #5 you are talking about several variables. If cause had values like

              "1"
              "2"
              "3"
              "4"

              then indeed it should be one byte variable after destring, replace. But then it's hard to follow why Andrew Musau's code didn't work,

              Comment

              Working...
              X