Lineplot of proportions over year in SPSS

Assume I have the following data

    DATA LIST FREE / sex (A) year.
m 2011
m 2011
m 2012
f 2011
f 2011
f 2011
f 2011
f 2012
f 2012

How can I plot a line of how the proportions of males and females change over the years. Not the absolute values and not the total percentages, but the percentages per year.

I also need a crosstab where the percentages per year are shown.

A syntax would be nice, thank you.

1 Answer

  1. Cosmo- Reply


    The crosstabs syntax would simply be CROSSTABS TABLE Year By Sex /CELLS = Col.. The graph you want you can actually build through the GUI, to use the summary functions per year though you need to specify the year variable as either ordinal or nominal.

    Here is the GGRAPH code the GUI printed out for me. Clean up as needed.

      /GRAPHDATASET NAME="graphdataset" VARIABLES=year[LEVEL=ORDINAL] COUNT()[name="COUNT"] sex 
      SOURCE: s=userSource(id("graphdataset"))
      DATA: year=col(source(s), name("year"), unit.category())
      DATA: COUNT=col(source(s), name("COUNT"))
      DATA: sex=col(source(s), name("sex"), unit.category())
      GUIDE: axis(dim(1), label("year"))
      GUIDE: axis(dim(2), label("Percent"))
      GUIDE: legend(aesthetic(aesthetic.color.interior), label("sex"))
      SCALE: linear(dim(2), include(0))
      ELEMENT: line(position(summary.percent(year*COUNT, base.coordinate(dim(1)))), 
        color.interior(sex), missing.wings())
    END GPL.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>