Announcement

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

  • Title graphs with alphabet letters in a loop

    Dear all,

    I am trying to produce a set of 16 graphs in a loop, giving them as title alphabet letters in sequential order.

    My task is as follows:

    I have a dataset with 2 independent variables (X1 and X2) and 2 dependent variables (Y1 and Y2). I am running regressions in a loop for each independent variable over each dependent variable using the permute command with 1000 repetitions.
    I then save the distribution of the coefficients obtained through the permutation in a dataset, as I want to use the distribution to make kdensity graphs. What I obtain in the end are 4 datasets, each one containing one distribution of the coefficient, and 4 graphs, one for each distribution.

    However I am not finding a way to title these graphs with alphabet letters in sequential order. That is, I want the first graph to be titled "A", the second graph to be titled "B", the third "C" and the fourth "D".

    Here is the code that I am trying to complete.

    foreach exp in X1 X2 {
    foreach dep in Y1 Y2 {

    permute `exp' _b[ `exp' ], saving( `exp'_`dep' ) reps(1000): reg `dep' `exp'

    preserve

    use `exp'_`dep' , clear

    twoway kdensity _pm_1, graphregion(color(white)) ytitle("Density") xtitle("") title()

    graph save "`exp'_`dep'.gph", replace

    restore

    }
    }

    Hope I have been clear in describing my issue and that somebody here have hints for a solution.

    Thanks, Davide

  • #2
    Silly example that works as long as you have less than 26 graphs:

    Code:
    local i = 1
    foreach exp in X1 X2 {
        foreach dep in Y1 Y2 {
            local letter `: word `i++' of `c(ALPHA)''
            twoway function y=x, title(`letter')
        }
    }
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Type

      Code:
      creturn list
      and especially look at the end of the results. People are often surprised to see several useful things.

      Comment


      • #4
        Your suggestions proved perfect. I have been able to reconstruct the code in both ways.
        Thank you very much Maarten Buis and Nick Cox !

        Comment

        Working...
        X