我正在运行基本的交叉表频率分析,其输出显示为三个镶板图表。输出中的所有内容都可以,除了我想知道每个面板中的个案数量,并且有一个" N = ..."图表中的任何位置可以是注释,也可以是标签的一部分,也可以是图表的顶部。实际上,任何地方都可以显示。
我暂时没有使用过SPSS语法,所以我有点难过。我的预感告诉我,我应该能够创建一个包含所有总和的新变量,并在每个面板的脚注中显示,但我不知道如何在SPSS中这样做。
谢谢。
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=RIncome COUNT()[name="COUNT"] YrOut_Group MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: RIncome=col(source(s), name("RIncome"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
DATA: YrOut_Group=col(source(s), name("YrOut_Group"), unit.category())
GUIDE: axis(dim(2), label("Percent"))
GUIDE: text.title(label("Income Ranges by Years Out"))
SCALE: linear(dim(2), include(0))
SCALE: cat(dim(3), include("4.00", "5.00", "10.00"))
ELEMENT: interval(position(summary.percent(RIncome*COUNT*YrOut_Group, base.all(acrossPanels()))), shape.interior(shape.square))
END GPL.
答案 0 :(得分:1)
首先,我会制作一些通常看起来像你的假数据来说明选项。
INPUT PROGRAM.
LOOP #i = 1 TO 1000.
COMPUTE RIncome = TRUNC(RV.UNIFORM(1,4)).
COMPUTE YrOut_Group = TRUNC(RV.UNIFORM(4,7)).
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
IF YrOut_Group = 6 YrOut_Group = 10.
现在,一个简单的选择是通过在label(COUNT)
语句中放置ELEMENT
来为每个栏标记计数。不是你想要的但是关闭。
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=RIncome COUNT()[name="COUNT"] YrOut_Group MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: RIncome=col(source(s), name("RIncome"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
DATA: YrOut_Group=col(source(s), name("YrOut_Group"), unit.category())
GUIDE: axis(dim(2), label("Percent"))
GUIDE: text.title(label("Income Ranges by Years Out"))
SCALE: linear(dim(2), include(0))
SCALE: cat(dim(3), include("4.00", "5.00", "10.00"))
ELEMENT: interval(position(summary.percent(RIncome*COUNT*YrOut_Group, base.all(acrossPanels()))), shape.interior(shape.square), label(COUNT))
END GPL.
我过去采用的一种方法是将每个面板的计数放在面板的标签中。我这样做是通过使用AGGREGATE
然后将YrOut_Group
替换为该变量的串联和每个组中的计数。
*Arbitrary label in each panel.
AGGREGATE OUTFILE=* MODE=ADDVARIABLES
/BREAK YrOut_Group
/TotalPanel = N.
STRING PanLab (A15).
COMPUTE PanLab = CONCAT(STRING(YrOut_Group,F2.0)," (N = ",STRING(TotalPanel,F3.0),")").
EXECUTE.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=RIncome COUNT()[name="COUNT"] PanLab MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: RIncome=col(source(s), name("RIncome"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
DATA: PanLab=col(source(s), name("PanLab"), unit.category())
GUIDE: axis(dim(2), label("Percent"))
GUIDE: text.title(label("Income Ranges by Years Out"))
SCALE: linear(dim(2), include(0))
SCALE: cat(dim(3))
ELEMENT: interval(position(summary.percent(RIncome*COUNT*PanLab, base.all(acrossPanels()))), shape.interior(shape.square))
END GPL.
不幸的是,当混合VARIABLES
部分中的聚合函数时很难将摘要放在面板中。因此,如果您真的想在面板中找到标签,我建议您自己总结数据并制作自己的标签。
*Placing a label in each panel.
*Is easier if you aggregate the data yourself.
DATASET DECLARE AggStats.
AGGREGATE OUTFILE = 'AggStats'
/BREAK YrOut_Group RIncome
/TotalRinc = N
/TotalPanel = FIRST(TotalPanel).
DATASET ACTIVATE AggStats.
AGGREGATE OUTFILE = * MODE=ADDVARIABLES
/BREAK
/TotalSamp = SUM(TotalRInc).
COMPUTE PercRinc = (TotalRinc/TotalSamp)*100.
MATCH FILES FILE = *
/FIRST = Flag
/BY YrOut_Group.
*Make label variable.
COMPUTE TotalPanel2 = TotalPanel.
IF Flag <> 1 TotalPanel2 = $SYSMIS.
FORMATS TotalPanel2 (F3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=RIncome YrOut_Group PercRinc TotalPanel2
MISSING=VARIABLEWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: RIncome=col(source(s), name("RIncome"), unit.category())
DATA: PercRinc=col(source(s), name("PercRinc"))
DATA: TotalPanel2=col(source(s), name("TotalPanel2"), unit.category())
DATA: YrOut_Group=col(source(s), name("YrOut_Group"), unit.category())
TRANS: LabXRinc = eval("2.00")
TRANS: LabYRinc = eval(13.5)
GUIDE: axis(dim(2), label("Percent"))
GUIDE: text.title(label("Income Ranges by Years Out"))
SCALE: linear(dim(2), include(0))
SCALE: cat(dim(3), include("4.00", "5.00", "10.00"))
ELEMENT: interval(position(RIncome*PercRinc*YrOut_Group), shape.interior(shape.square))
ELEMENT: point(position(LabXRinc*LabYRinc*YrOut_Group), label(TotalPanel2))
END GPL.
答案 1 :(得分:0)
@ andy-w
我得到了图表来做我想做的事情,除了现在我在轴上丢失了标签。
完全按照上面的代码进行一些小修改。这是新代码。
DATASET DECLARE AggStats.
AGGREGATE OUTFILE = 'AggStats'
/BREAK RHEDS_YrOut_Group RIncome
/TotalRinc = N
/TotalPanel = FIRST(TotalPanel).
DATASET ACTIVATE AggStats.
AGGREGATE OUTFILE = * MODE=ADDVARIABLES
/BREAK
/TotalSamp = SUM(TotalRInc).
COMPUTE PercRinc = (TotalRinc/TotalSamp)*100.
MATCH FILES FILE = *
/FIRST = Flag
/BY RHEDS_YrOut_Group.
*Make label variable.
COMPUTE TotalPanel2 = TotalPanel.
IF Flag <> 1 TotalPanel2 = $SYSMIS.
FORMATS TotalPanel2 (F3.0).
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=RIncome PercRinc RHEDS_YrOut_Group MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: RIncome=col(source(s), name("RIncome"), unit.category())
DATA: PercRinc=col(source(s), name("PercRinc"))
DATA: TotalPanel2=col(source(s), name("TotalPanel2"), unit.category())
DATA: RHEDS_YrOut_Group=col(source(s), name("RHEDS_YrOut_Group"), unit.category())
TRANS: LabXRinc = eval("5")
TRANS: LabYRinc = eval(20)
GUIDE: axis(dim(2), label("Percent"))
GUIDE: axis(dim(3), label("HEDS Years out"), opposite())
GUIDE: axis(scale(RIncome))
GUIDE: legend(aesthetic(aesthetic.color), null())
SCALE: linear(dim(2), include(0))
SCALE: cat(aesthetic(aesthetic.color), include("4", "5", "10"), map(("4", color.lightgreen), ("5", color.MediumSpringGreen), ("10", color.green)))
TRANS: RIncome_TRANS = collapse(category(RIncome), minimumPercent(0.5), sumVariable(COUNT), otherValue("Other"))
ELEMENT: interval(position(RIncome*PercRinc*RHEDS_YrOut_Group), shape.interior(shape.square), color(RHEDS_YrOut_Group))
ELEMENT: point(position(LabXRinc*LabYRinc*RHEDS_YrOut_Group), label(TotalPanel2), color(RHEDS_YrOut_Group))
END GPL.
我无法在此处发布输出,因为我还没有得到10分。但是从代码中你可以看出我仍然试图将N =包含在顶部。