Announcement

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

  • Problem with option xline in twoway graph by saving the graph


    I have a dataset concerning export dynamics over 61 countries from 1994-2014 with around 19 different variables. Additional I would like to investigate if certain natural events (e.g. flood, extreme temperature) influence the export dynamic. For the export dynamic I have for example the variable “TA1_c_y” which are the total exporting firms per country and year.
    I graph the pattern of TA1_c_y over time. Additional, I would like to mark these years where a natural event happened. I am doing this by the option “xline”, where I insert different xlines with different colors to distinguish different types of natural events.
    For the necessary information for the option xline I use the command “levelsof” to get the information which event happened in which country and at which time point. I save the results in a global macro $g1`m’, where 1 indicates the type of natural event and `m’ indicates the country. This all works fine.
    When I plot the graph with the option “saving(titel, asis)” is see all xlines on the right position (picture 1), however, in the saved graph sometimes an additional line appears on a random places (outside on the left side of the graph picture 2). It seems so that the random line is not only one line but many overlaying lines.
    Do you know, how to solve this problem or another option to mark the time points where a natural disaster happened? I use Stata15. My programming code is:


    . forval i = 1/1 {
    2. local label: var label A`i'
    3.
    . foreach m of numlist 6 {
    4. local label_c: label(c_cat) `m'
    5. twoway line TA`i'_c_y y if c_y_group==1 & c_cat==`m', ///
    > sort(y) ///
    > title(`label'_per_y_c_and_natdis) ///
    > ylabel(,angle(0)) ///
    > xline(0 ${g1`m'}, lcolor(maroon)) ///
    > xline(0 ${g2`m'}, lcolor(brown)) ///
    > xline(0 ${g3`m'}, lcolor(cyan)) ///
    > xline(0 ${g4`m'}, lcolor(red)) ///
    > xline(0 ${g5`m'}, lcolor(blue)) ///
    > xline(0 ${g6`m'}, lcolor(yellow)) ///
    > xline(0 ${g7`m'}, lcolor(green)) ///
    > xline(0 ${g8`m'}, lcolor(black)) ///
    > xline(0 ${g9`m'}, lcolor(ltblue)) ///
    > xline(0 ${g10`m'}, lcolor(cranberry)) ///
    > xline(0 ${g11`m'}, lcolor(orange)) ///
    > name(g`i'`m', replace) ///
    > saving(A`i'_per_y_c_and_natdis_country`m', asis replace)
    6.
    . }
    7.
    . }
    file A1_per_y_c_and_natdis_country6.gph saved

    Thanks!
    Attached Files
    Last edited by Markus Simbuerger; 05 Jun 2018, 02:26. Reason: I forgot to mention that I included also a zero in the command xline, otherwise I would get the error message "something required"

  • #2
    If you get the message "something required" when specifying the xline option without the zero, that means your global isn't defined. There shouldn't be a zero in there, because that tells stata to draw an xline at zero. Quite possibly Stata is smart enough to ignore it when drawing the graph first, but not when saving it. Can you check if all your globals work properly?

    Comment


    • #3
      My globals seems to be well defined, it could just happened that nothing is stored in my globals because no natural event happened at the time point in this country, therefore I included the zeros in the xline option to avoid the error message "something required". Stata seems also to be smart enough to igore the zero. However, I have also the problem that this random line does not only occur on the left side of the graph but also sometimes somewhere in the middle?!

      Comment


      • #4
        Without a working example (e.g. see the FAQ on dataex), it's hard to see where the problem arises, although my money is still on the mix between zeroes you don't want and globals. Have you tried making Stata code for you? I.e. generate the xline part of the graph command in a local based on whether the global is non-empty? That way, you don't need to use the zero trick.

        Comment


        • #5
          Thank you for your effort. The issue is that I have 61 different countries and to avoid that my global or local are non empty I would have to write 61 individual codes for each graph. However, I solved my problem in creating new variables with the necessary information and make now a twoway line and scatter graph combined.

          Comment

          Working...
          X