You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SPSS并排频率表制作求助:学生服务A/B双侧计数表生成需求

To create the side-by-side frequency table you need (including blank categories) in SPSS, here's a step-by-step solution that addresses your requirement clearly:

Step 1: Recode Empty Strings to a Visible Category

First, we’ll convert the empty string values in ServiceA and ServiceB to a labeled category ([Blank]) so they appear explicitly in our table (SPSS doesn’t treat empty strings as visible categories by default):

* Recode empty strings to "[Blank]".
RECODE ServiceA ServiceB ('' = '[Blank]') (ELSE = COPY).

Step 2: Define Value Labels for All Possible Categories

Next, we’ll define value labels covering every category we expect to see (including those that only appear in one service). This ensures SPSS includes all categories in the table, even if they have zero counts in one of the services:

* Define value labels for all possible service categories.
VALUE LABELS ServiceA ServiceB
  '[Blank]' '[Blank]'
  'ABC' 'ABC'
  'EFG' 'EFG'
  'XYZ' 'XYZ'.

Step 3: Generate the Side-by-Side Frequency Table

Finally, use the TABLES command to create the desired table. The EMPTY=INCLUDE parameter ensures we keep categories with zero counts, and FORMAT=NOTOTAL removes unnecessary total rows:

* Create side-by-side frequency table with counts.
TABLES
  /TABLE [CATEGORY] BY (ServiceA ServiceB)
  /COUNT=YES
  /FORMAT=NOTOTAL
  /CATEGORIES VARIABLES=ServiceA ServiceB ORDER=A KEY=VALUE EMPTY=INCLUDE.

Alternative Approach: Aggregate and Merge Datasets

If you prefer more control over the output (like exporting to a dataset for further manipulation), you can aggregate counts for each service and merge the results:

* Aggregate counts for ServiceA.
AGGREGATE
  /OUTFILE='temp_serviceA.sav'
  /BREAK=ServiceA
  /CountA=N.

* Aggregate counts for ServiceB.
AGGREGATE
  /OUTFILE='temp_serviceB.sav'
  /BREAK=ServiceB
  /CountB=N.

* Create a master list of all categories.
DATA LIST FREE /Category (A10).
BEGIN DATA
"[Blank]"
"ABC"
"EFG"
"XYZ"
END DATA.

* Merge counts from both services into the master category list.
MATCH FILES /FILE=* /TABLE='temp_serviceA.sav' /BY Category=ServiceA.
MATCH FILES /FILE=* /TABLE='temp_serviceB.sav' /BY Category=ServiceB.

* Replace missing counts with 0 and clean up variables.
RECODE CountA CountB (SYSMIS=0).
DROP ServiceA ServiceB.

* Display the final table.
LIST Category CountA CountB.

Both methods will produce a table where each row is a service category (including [Blank]), with columns showing the count for ServiceA and ServiceB respectively.

内容的提问来源于stack exchange,提问作者Larry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:16:02