Announcement

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

  • plot graph with conditions

    Hi Statalist,

    I am trying to plot a graph only for countries that are in asia, I have a dummy variable "Asia" (=1 if country is in Asia), and other variable "Country" "year" and "Trade_flows"
    I am struggling to plot the graph with year in the horizontal axis and Trade_flows in the vertical axis but only for countries in Asia (thus when Asia==1)
    I use "twoway (line Trade_flows year) if Asia==1" but I get a graph with multiple line everywhere (see enclosed) and I am trying to group them in one single line.
    Thanks a lot!

    Best regards,

    John
    Attached Files
    Last edited by dupont john; 07 Jan 2016, 15:53.

  • #2
    No code to comment on, no data to experiment with (FAQ Section 12) but on this information you should be adding

    Code:
    if Asia == 1
    to your graph command.

    Comment


    • #3
      Hi Nick,

      Sorry for the lack of info! I edited my comment above and tried to add as much information as I could.
      Thanks for your help!

      Best,

      John

      Comment


      • #4
        The data are joined in order of observations. You need a different sort order, possibly

        Code:
        sort Asia Country year
        It seems also that you have earlier data for non-Asian countries. To get a better graph you may need to do something like this

        Code:
        preserve 
        keep if Asia == 1 
        sort Country year 
        line Trade_flows year, c(L) 
        restore

        Comment


        • #5
          Hi Nick!

          Thanks a lot for your reply!
          When I type those commands, I still multiple line (one for each country) if there anyway I could group then in order to have only one single for "Asia" and not one line for each country in asia?
          Thanks!

          Best,

          John

          Comment


          • #6
            It is up to you to collapse your yearly data for the countries in Asia into a single value for each year and then plot that data. See help collapse for further details. Something like the following might be what you need.
            Code:
            collapse (sum) TradeFlows if Asia==1, by(year)

            Comment

            Working...
            X