Announcement

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

  • Graph dummy variable

    Dear users
    Hope you are doing well.
    I have a panel data. My Dep is dummy (0, 1), and I have a dummy for Year and Country as well.
    Please, how can I make:
    1. Line graph for only when my dep equal to 1. I mean I want to make a graph to see the increasing in 1 across years.
    2. I would like also to know how can I make a bar graph for Dep only when equal 1 across Country( to know which country have more 1 compared to others ) . Thanks a lot
    Kind Regards

  • #2
    Not quite sure if this is what you're looking for (a -dataex- would be useful), but maybe:
    Code:
    bys year: egen totaldummyyear = total(dummy)
    bys id: egen totaldummyid = total(dummy)
    twoway line totaldummyyear year,sort(year) name("Line")
    twoway bar totaldummyid id,name("Bar")

    Comment


    • #3
      Dear @Ali Atia Thank you so much for your help. I appreciate that too much.
      More specifically, I need to do like the these pictures, please. The first one each color has dummy variable and the X line is the year ( but instead of bar , I would like to do it like two lines ) . The second one ( X line the country and Y line the dummy). Thank You so much .


      Attached Files

      Comment


      • #4
        #3 is an excellent answer to #1. Now you're asking for something different,

        The first graph is a line graph of the frequencies of both 0 and 1, if I understand you correctly.


        Code:
        bys year dummy: gen count = _N 
        separate count, by(dummy) veryshortlabel 
        line count0 count1 year, sort
        It's difficult to know what the second graph is. The frequencies of 1 by country?


        Comment


        • #5
          Dear @Nick Cox
          Thank you so much for your reply, Thanks.
          I would like to explain you the thing.
          My study has three dummy.
          The first graph is not 0, 1, is two dummy variables with year (but I want to take only the 1 for each dummy). I want to add the year in xline and the dummy with yline. Well, in the graph attached looks like bar, I would like to do it line for each dummy in the same graph.
          The second one is (one dummy variable) in x line and counties in the y line (also I want to take only the 1 not zero for each country) but if the country variable string is it possible? Thank you so much in advance.

          Comment


          • #6
            Sorry, but your wording isn't very clear to me.

            Please read the FAQ Advice https://www.statalist.org/forums/help#stata and give a data example and explain in terms of that.

            Perhaps what you want for the first graph is something like

            Code:
            bysort year : egen count1 = total(dummy1)
            by year: egen count2 = total(dummy2)
            
            line count1 count2 year, sort
            and the second graph may be something similar
            Last edited by Nick Cox; 19 Dec 2020, 06:12.

            Comment

            Working...
            X