Announcement

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

  • Changing format of ylabels in a scheme

    Hi,

    I want to add a parameter to a scheme to make the ylabels of a graph display in a given format. I think most of the time %9.0fc is fine for me, so if I can only have one then i'll go with that; but if it's additionally possible to add in dynamic elements (i.e. "if yvar <5 ylabel format is %9.1f") then i can set up a few different options that would remove 90% of the instances where I have to hardcode graph options.

    Does anyone know how to do this? I've looked through a few schemes that automatically display ylabels with commas for every third digit, but can't seem to see which line(s) of code is producing that result.

    Also, is it just me or are schemes really under-documented? When I look at a scheme you can see parameters for gsize, alignstroke, axisstyle, yesno draw_major_grid, etc., and can pretty much figure out what all the entries are doing based on knowledge of twoway options, but the help file for schemes doesn't go into nearly so much detail. It seems to be more of a resource to help you use other people's schemes, not to create your own. Am I looking in the wrong place?



  • #2
    I don't know where you are exactly looking , so I cannot tell you if your are looking in the wrong place. help scheme files and help scheme entries is where I look for documentation of scheme files.

    I don't think you can set a default format in a scheme file, the default is to just take the format of the variable that is being plotted.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Ok that's helpful. Thanks Maarten -- i was looking in help scheme.

      Shame that the ylabels can't be formatted on the fly within schemes. I'm not sure i'd want to default my dataset to %....fc even if that was possible, so it looks like i am forever going to have to write ylab(,format(%9.0fc)) when I make graphs in Stata. Maybe I should set up some hot-keys

      Comment


      • #4
        Or you can change the format of the variable that will be on the y axis once and be done...

        Comment


        • #5
          Thanks Nicholas.

          Maybe i'm missing something but that won't that still mean I have to reformat the specific variable that's going to be on my y-axis every time I make a graph (and want the ylabel to be %9.0fc). The only difference is whether I do it in the twoway ylabel options or directly on the y-variable that i'm plotting, right?

          If yes, that doesn't quite solve for what i want -- which is to make my graphs display with %9.0fc on the yaxis labels automatically (unless otherwise specified)

          Comment


          • #6
            No, you only need to set the display format for a variable once, and it is permanent (until you reset it differently); it will save with the dataset as well. So: something like this:

            Code:
            format y1 y2 y3 y4 %9.0fc
            scatter y1 ...
            scattery y2 ...
            etc.
            I think the philosophy is that graph schemes contain styling information that would apply to any graph. The display format of the axis labels will depend on the scaling of the variable, so logically attaches to the variable, not the scheme.

            Comment


            • #7
              Right. I see. Thanks for this Nicholas.

              Dynamic schemes would be great; your proposed approach would help though in that I would only have to format the variables once per do-file instead of once per graph, but I *would* have to do it anew for each do-file.

              Comment


              • #8
                I don't see why that would be the case: The format is stored with the data, so you only have to do this once when you create your analysis datafile.

                The main strategy is to not try to do everything in one .do file. These tend to make way too big, unreadable, and hard to maintain. Instead, you split up your project in multiple .do files. At least, you separate the data preparation part from the analysis part. In the data preparation .do file you create and save your analysis datafile (you obviously keep your original data intact). In the analysis .do you open the analysis datafile and create graphs, compute descriptive statistics and estimate whatever model interests you. In practice the dataprepation .do file is usually multiple .do files. So, as long as you set the format in the data preparation .do file(s) you are done: you no longer have to touch the format in your analysis .do files.
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment


                • #9
                  Thanks Maarten. I appreciate that. And, yes, every one of my projects has a robust folder and code structure; the latter of which is broken down into pre-trial work (exploratory analysis, power calculations, randomization, data export, etc.) and post-trial work (cleaning and analysis), and within each of those I typically have three do-files (one that is a directory that sets a flexible path, system agnostic; one for cleaning; and one for model specification). And every project has a unique code and files (including do-files, datasets, graphs, etc.) are named appropriately (e.g. uniquecode_pretrial_cleaning.do) to avoid the otherwise inevitable _final_FINAL_ACTUALLYTHELASTONE.do... I wouldn't worry about my code base structures

                  And while Nicholas's is a helpful suggestion (thank you again btw!), I will still have to format my data 'manually' (i.e. with new code) for each dataset. Not in each do-file, you're right about that, but what I was looking for (cf #1) was to add the ylabel formatting to a scheme so I literally never have to hard code format var %9.0fc or ylabel(,format(%9.0fc)) again.

                  Anyway, really appreciate your guys' input! Have a nice day

                  Comment

                  Working...
                  X