+ Reply to Thread
Results 1 to 7 of 7

Thread: [Stata] - String values on axis of graph

  1. #1
    Points: 1,640, Level: 23
    Level completed: 40%, Points required for next Level: 60

    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [Stata] - String values on axis of graph



    Hi there,

    I would like to create a graph with the value of a string variable in the x axis.

    Right now I can do

    line price id

    and I get a graph of price against id (which is a numerical variable). However, I would like to have the value of a string variable on the x-axis so that I can have, for example, price against a variable {a b c d e f ...}

    Any help please...

  2. #2
    Points: 2,352, Level: 29
    Level completed: 35%, Points required for next Level: 98

    Location
    Paris
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    I think that what you are looking for is smtg like this:

    graph bar (mean) price, over(id)

    Hope this helps!

    Etienne

  3. #3
    Points: 1,640, Level: 23
    Level completed: 40%, Points required for next Level: 60

    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No I am trying to do a line graph with the ticks labeled by the vales in a string variable
    Last edited by kungal; 09-04-2010 at 12:08 PM.

  4. #4
    Points: 2,352, Level: 29
    Level completed: 35%, Points required for next Level: 98

    Location
    Paris
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So you do want to plot price against id but you want to label the x-axis with a label associated to id? If this is what you want to do, then you should:

    1/ define the label for id. If the label is in a string variable you can store the different values using "levelsof". Then you just have to use "label define" and "label val"

    2/ use the options for xlabel. Smtg like this: "line price id, xlabel(..., valuelabel)

    Or maybe I still don't understand what you want to do.

  5. #5
    Points: 1,640, Level: 23
    Level completed: 40%, Points required for next Level: 60

    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, that is what I want to do. Thanks for your help but I still don't understand how this is going to work.

    I have about 100 000 observations on the line graph and I need to have some words like "one", "two", ..., "ten" (for example) on the horizontal axis (there are far fewer words than id numbers).

    I know I can use xlabel to label every 10 000th tick with a number but I need to have a word instead.

  6. #6
    Points: 2,352, Level: 29
    Level completed: 35%, Points required for next Level: 98

    Location
    Paris
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Then you can label only some values of your variable id. For instance:

    label define example 1 "One" 100 "Two" etc. 100000 "Ten"
    label val id example

    and then line price id, xlabel(1 100 ... 100000, valuelabel)

  7. #7
    Points: 1,640, Level: 23
    Level completed: 40%, Points required for next Level: 60

    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Brilliant, works perfectly. You are a genius

    Many thanks

+ Reply to Thread

Similar Threads

  1. add values in a barplot graph.. how ?
    By petros20 in forum R
    Replies: 0
    Last Post: 03-23-2011, 09:17 AM
  2. [STATA] Twoway scatter graph help
    By georgina in forum Stata
    Replies: 2
    Last Post: 08-31-2010, 08:03 PM
  3. [Stata] - Convert string to date
    By gihund in forum Stata
    Replies: 1
    Last Post: 03-10-2010, 01:08 AM
  4. incidence graph in stata
    By robo_2 in forum Stata
    Replies: 0
    Last Post: 02-15-2010, 01:19 AM
  5. STATA Problem with string variables
    By antonis11 in forum Stata
    Replies: 1
    Last Post: 02-13-2010, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats