Announcement

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

  • How to use value label as a graph title in forvalues loop

    Dear Stata users

    I want the value label to be the title of the graph, and I use the following code. Instead of displaying the name of the country(Iso) in the graph it display the numeric value
    Any help is appreciated

    forvalues i= 1/10 {
    graph twoway bar m_stock year if iso==`i', fcolor(teal) yaxis(1) yscale(range(0) axis(1)) /*
    */ || line ex year if iso==`i', sort yaxis(2) yscale(range(0) axis(2)) /*
    */ ytitle("", size(small) margin(small)) yscale(titlegap(*10.4)) /*
    */ ytitle("", axis(2)) /*
    */ xtitle("") /*
    */ xlabel(,labsize(small)) ylabel(,labsize(small))/*
    */xscale( r(1998 2016)) xlab(1998 (4)2016)/*
    */graphregion(color(white))/*
    */ title("`i'") /*
    */legend(off)
    graph export "E_vs_m_`i'.pdf", as(pdf) replace
    }
    *
    Thanks

  • #2
    Here is sample code that may point you in a helpful direction.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . forvalues i=0/1 {
      2. local v : label (foreign) `i'
      3. display "`i' is `v'"
      4. }
    0 is Domestic
    1 is Foreign
    
    .

    Comment


    • #3
      Dear William

      Thanks. Now it works

      Best

      Comment


      • #4
        Consider also

        Code:
        graph twoway bar m_stock year,  by(iso) fcolor(teal) yaxis(1) yscale(range(0) axis(1)) 
        * and so on

        Comment

        Working...
        X