Announcement

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

  • Questions

    hello everyone,

    I am new to Stata and have a question with regard to variable creation. I am trying to label the axis using the actual province abreviations rather than the designated number in the data sheet. the code I am using is:

    keep prov hrlyearn
    label define provincelables 10 "NL" 11 "PEI" 12 "NS" 13 "NB" 24 "QC" 35 "ON" 46 "MB" 47 "SK" 48 "AB" 59 "BC"
    graph twoway scatter hrlyearn prov

    This code generates the graph but has the provinces numbers along the axis rather than the abreviations




  • #2
    It is not enough to define the label. You have to also tell Stata what variable(s) to apply the label to. Stata does not try to guess that. It requires an additional command:
    Code:
    label values prov provincelables

    Comment


    • #3
      Thanks, but I cannot seem to get it to work still this is what I have down for the code I know that I am still missing something


      keep prov hrlyearn
      label define provincelables 10 "NL" 11 "PEI" 12 "NS" 13 "NB" 24 "QC" 35 "ON" 46 "MB" 47 "SK" 48 "AB" 59 "BC"
      label values prov provincelables
      graph twoway scatter hrlyearn prov

      Comment


      • #4
        Yes, sorry. In addition to all that, you have to direct -scatter- to use the value labels:
        Code:
        graph twoway scatter hrlyearn prov, xlabel(, valuelabels)

        Comment


        • #5
          Thanks you. It works for only the first xvalue of NL being equal to 10, but wont apply to any of the others

          keep prov hrlyearn
          label define provincelables 10 "NL" 11 "PEI" 12 "NS" 13 "NB" 24 "QC" 35 "ON" 46 "MB" 47 "SK" 48 "AB" 59 "BC"
          label values prov provincelables
          graph twoway scatter hrlyearn prov, xlabel(, valuelabels)

          Comment


          • #6
            I don't understand why. This is most likely some problem with your data. Please use the -dataex- command to supply representative example from your data set. Be sure that it includes observations from each of the provinces. Also, run the code with just the example data, to make sure that it replicates the problem you are encountering. If you do that, I will try to troubleshoot the problem.

            If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

            Comment


            • #7
              I don't think that scatter will ever unilaterally decide on 10 11 12 13 24 35 46 37 48 59 as the x axis labels to use. 10 is being chosen as a "nice number" (here a term of art) but none of the others is likely to be chosen in that way. You need to spell those out in the command, so

              Code:
              xlabel(10 11 12 13 24 35 46 37 48 59, valuelabels)

              A deeper point is why you want those literal values on an axis. I recognise provinces of Canada in roughly East-West order.

              10 "NL" 11 "PEI" 12 "NS" 13 "NB" 24 "QC" 35 "ON" 46 "MB" 47 "SK" 48 "AB" 59 "BC"

              Depending on the rest of the data -- and I agree with Clyde Schechter that we need a data example -- something like

              Code:
              graph dot  hrlyearn, over(prov)
              may be more useful.

              For future threads, please choose informative titles, not "Questions" and the like, as already advised at https://www.statalist.org/forums/help#topiclines

              Comment

              Working...
              X