Announcement

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

  • Loop and Graph combine

    Hello,

    I went through the forum on looping and graph combining and still couldn't figure out the error.
    Essentially, I have variables from years 2006 to 2011 and would like to create 5 graphs for each variable plotting time t on the x-axis and time t+1 on the y-axis.
    Then, for each variable, I will combine the 5 graphs and name it by the variable.

    The codes are below:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(female_prop male_prop child_prop year)
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2006
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2007
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    .29545453 .3181818 .3863636 2008
    end
    Code:
    global varlist "female_prop male_prop child_prop"
    foreach var in $varlist {
        bysort year: gen `var'1=`var'[_n+1]
    }
    
    local j=2006
    foreach var in $slc_var {
        graph twoway scatter `var'1 `var' if year<=2011, ///
        title(Year `j') ///
        xtitle("t") ytitle("t+1") ///
        name(g`var'_`j', replace) ///
        graphregion(fcolor(white)) 
        local j=`j'+1
        graph combine g`var'_*, row(6) cols(3), title("`var'")
        graph save "`var'_time.png", replace
    }
    Thank you very much in advance.

  • #2
    The code is (apparently) legal but does nothing useful because the global slc_var is not defined.

    Comment

    Working...
    X