Announcement

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

  • How to make a horizontal bar graph which shows whether a dummy is equal to one or zero at a given time?

    Dear all,

    The variables relevant for the graph are a treatment dummy called treat, date (in years) and a categorical variable, called school, that says which school an observation belongs to (it can take 8 values/schools). I would like to create a horizontal bar graph that has a bar for each of these schools and each bar should be able to take three colours (depending on whether the dummy is one, zero or if its missing for an observation) across time.

    I´m relatively new to Stata and I could not find information on this type of graph anywhere, so I´m happy about any advice!

    Thanks!


  • #2
    Example data please

    Comment


    • #3
      Hi Nick, please find attached an example of the data (only 5 schools here).
      Attached Files

      Comment


      • #4
        Here is Robbe's example data in approved form. See https://www.statalist.org/forums/help#stata for why we ask for dataex code, not .dta attachments.

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(school year treat)
        1 1950 1
        1 1951 1
        1 1952 1
        1 1953 1
        1 1954 1
        1 1955 1
        1 1956 1
        1 1957 0
        1 1958 0
        1 1959 0
        1 1960 1
        1 1961 1
        1 1962 1
        1 1963 1
        1 1964 1
        1 1965 1
        1 1966 1
        1 1967 0
        1 1968 0
        1 1969 0
        1 1970 0
        1 1971 0
        1 1972 .
        1 1973 .
        1 1974 .
        1 1975 .
        1 1976 .
        1 1977 .
        1 1978 .
        1 1979 .
        1 1980 .
        1 1981 .
        1 1982 0
        1 1983 0
        1 1984 0
        1 1985 1
        1 1986 1
        1 1987 1
        1 1988 1
        1 1989 1
        1 1990 0
        1 1991 0
        1 1992 0
        1 1993 0
        1 1994 .
        1 1995 .
        1 1996 .
        1 1997 .
        1 1998 .
        1 1999 0
        1 2000 0
        1 2001 0
        1 2002 0
        1 2003 0
        1 2004 1
        1 2005 1
        1 2006 1
        1 2007 1
        1 2008 1
        1 2009 1
        1 2010 1
        2 1950 1
        2 1951 1
        2 1952 1
        2 1953 1
        2 1954 0
        2 1955 0
        2 1956 0
        2 1957 .
        2 1958 .
        2 1959 .
        2 1960 .
        2 1961 .
        2 1962 0
        2 1963 0
        2 1964 0
        2 1965 0
        2 1966 0
        2 1967 0
        2 1968 0
        2 1969 0
        2 1970 1
        2 1971 1
        2 1972 1
        2 1973 1
        2 1974 1
        2 1975 1
        2 1976 1
        2 1977 1
        2 1978 1
        2 1979 1
        2 1980 1
        2 1981 0
        2 1982 0
        2 1983 0
        2 1984 0
        2 1985 0
        2 1986 0
        2 1987 0
        2 1988 0
        2 1989 1
        2 1990 1
        2 1991 1
        2 1992 1
        2 1993 1
        2 1994 1
        2 1995 1
        2 1996 1
        2 1997 1
        2 1998 1
        2 1999 1
        2 2000 1
        2 2001 1
        2 2002 1
        2 2003 1
        2 2004 1
        2 2005 1
        2 2006 1
        2 2007 1
        2 2008 1
        2 2009 1
        2 2010 1
        3 1950 0
        3 1951 0
        3 1952 0
        3 1953 0
        3 1954 0
        3 1955 0
        3 1956 .
        3 1957 .
        3 1958 .
        3 1959 .
        3 1960 .
        3 1961 .
        3 1962 .
        3 1963 .
        3 1964 .
        3 1965 .
        3 1966 .
        3 1967 0
        3 1968 0
        3 1969 0
        3 1970 0
        3 1971 0
        3 1972 1
        3 1973 1
        3 1974 1
        3 1975 1
        3 1976 1
        3 1977 1
        3 1978 1
        3 1979 1
        3 1980 1
        3 1981 1
        3 1982 1
        3 1983 1
        3 1984 1
        3 1985 1
        3 1986 1
        3 1987 1
        3 1988 1
        3 1989 1
        3 1990 1
        3 1991 1
        3 1992 1
        3 1993 1
        3 1994 1
        3 1995 1
        3 1996 1
        3 1997 1
        3 1998 1
        3 1999 1
        3 2000 1
        3 2001 1
        3 2002 1
        3 2003 1
        3 2004 1
        3 2005 1
        3 2006 1
        3 2007 1
        3 2008 1
        3 2009 1
        3 2010 1
        4 1950 .
        4 1951 .
        4 1952 .
        4 1953 .
        4 1954 .
        4 1955 .
        4 1956 .
        4 1957 .
        4 1958 .
        4 1959 .
        4 1960 .
        4 1961 .
        4 1962 .
        4 1963 .
        4 1964 0
        4 1965 0
        4 1966 0
        4 1967 0
        4 1968 0
        4 1969 0
        4 1970 0
        4 1971 0
        4 1972 .
        4 1973 .
        4 1974 .
        4 1975 1
        4 1976 1
        4 1977 1
        4 1978 1
        4 1979 1
        4 1980 1
        4 1981 1
        4 1982 1
        4 1983 1
        4 1984 1
        4 1985 1
        4 1986 1
        4 1987 1
        4 1988 1
        4 1989 1
        4 1990 1
        4 1991 1
        4 1992 1
        4 1993 0
        4 1994 0
        4 1995 0
        4 1996 0
        4 1997 0
        4 1998 0
        4 1999 0
        4 2000 0
        4 2001 1
        4 2002 1
        4 2003 1
        4 2004 1
        4 2005 1
        4 2006 1
        4 2007 1
        4 2008 1
        4 2009 1
        4 2010 1
        5 1950 1
        5 1951 1
        5 1952 1
        5 1953 1
        5 1954 1
        5 1955 1
        5 1956 1
        5 1957 1
        5 1958 1
        5 1959 1
        5 1960 1
        5 1961 0
        5 1962 0
        5 1963 0
        5 1964 0
        5 1965 0
        5 1966 1
        5 1967 1
        5 1968 1
        5 1969 1
        5 1970 1
        5 1971 1
        5 1972 1
        5 1973 0
        5 1974 0
        5 1975 0
        5 1976 0
        5 1977 1
        5 1978 1
        5 1979 1
        5 1980 0
        5 1981 0
        5 1982 0
        5 1983 0
        5 1984 0
        5 1985 0
        5 1986 0
        5 1987 0
        5 1988 0
        5 1989 0
        5 1990 0
        5 1991 0
        5 1992 0
        5 1993 1
        5 1994 1
        5 1995 1
        5 1996 1
        5 1997 1
        5 1998 1
        5 1999 1
        5 2000 1
        5 2001 1
        5 2002 1
        5 2003 1
        5 2004 1
        5 2005 0
        5 2006 0
        5 2007 0
        5 2008 0
        5 2009 0
        5 2010 0
        end
        label values school School
        label def School 1 "A", modify
        label def School 2 "B", modify
        label def School 3 "C", modify
        label def School 4 "D", modify
        label def School 5 "E", modify
        label values treat Treat
        label def Treat 0 "Not treated", modify
        label def Treat 1 "Treated", modify
        Here is an attempt at what I think is wanted. I'd advise leaving the missings blank as the most visually effective method.

        Code:
        tabplot school year, barwidth(1) separate(treat) bar2(lcolor(blue) fcolor(blue*0.2)) bar1(lcolor(red) fcolor(red*0.2)) legend(on order(3 "Yes"  2 "No") pos(12)) xla(1950(10)2010) xasis note("") subtitle("")
        tabplot is from the Stata Journal.


        Click image for larger version

Name:	milian.png
Views:	1
Size:	32.0 KB
ID:	1676602

        Comment


        • #5
          Thank you very much Nick! This is really helpful.

          Comment

          Working...
          X