Free Essay

Officer

In:

Submitted By huyunyi
Words 1502
Pages 7
SPSS数据处理基础 [pic]

[pic]

第1章 SPSS数据的录入

SPSS既是Statistical Package for the Social Science(社会科学统计软件包)的缩写,也是Statistical Product and Service Solution (统计产品与服务解决方案)的缩写,是世界上几大统计分析软件(SPSS、SAS、S-plus/R、STATA、GUASS)中使用最广泛,界面最友好,操作最方便的统计软件,其强大的功能和易掌握性对于非统计专业特别是经济和管理专业的学生和工作人员,是一个不可多得的统计分析和数据处理的好工具、好助手。本书将基于SPSS 17.0给读者介绍SPSS的强大功能,关于SPSS的安装和一般Windows应用软件没有什么不同,让我们从SPSS的基础——建立数据文件和录入数据开始吧。

1 SPSS数据文件的建立和数据录入

在本节中我们从一个简单例题入手,让读者了解SPSS是如何建立数据文件,以及如何录入数据的。
例1-1下表是某保险机构收集的车险投保人数据,请根据数据特点建立SPSS数据文件。

表1.1车险投保人的数据[1]

|性别 |年龄 |交通事故数 |性别 |年龄 |交通事故数 |
|男 |23 |2 |女 |25 |1 |
|男 |35 |1 |女 |24 |3 |
|男 |26 |1 |女 |31 |1 |
|男 |25 |0 |女 |26 |0 |
|男 |28 |2 |女 |26 |0 |
|男 |31 |1 |女 |29 |0 |
|男 |23 |1 |女 |22 |2 |
|男 |31 |3 |女 |25 |5 |
|… |… |… |… |… |… |

首先,进入SPSS软件,双击桌面上的SPSS图标,或者从“开始”菜单→“所有程序”→“SPSS Statistics”→“SPSS Statistics”图标进入软件,将会看到如图1-1的软件界面:
[pic]
• 在启动SPSS后,一般先进入一个导航框,其中有一些常用操作和上次使用过的数据文件和结果文件等,不用太过理会导航框,直接选择Cancel就可以进入软件主界面。
[pic]

在软件界面中,除了看到与一般软件相同的菜单、快捷按钮以外,还可以看到灰色的“变量(英文界面是Var)”和“1、2、3”分别代表变量和案例,由于我们还没有建立任何变量和案例,所以这些都是灰色的。在界面的右上角可以看到“Visible:0 of 0 Variables”表明数据中共有0个变量,可见的是0个变量。接下来我们就在这个操作界面中建立变量和案例。
[pic] 关于变量和案例,分别对应操作界面的列和行,这与一般的数据库软件相同,有些书称为变量和记录,统计上通常称为指标和样本,意思大同小异。
[pic]
图 1-1 SPSS软件界面

建立SPSS数据文件和一般的数据库文件建立的考虑基本相同,主要是两个步骤:
Step1:定义文件的数据结构;
Step2:录入数据。

在Step1中,重点需要考虑用多少个变量,每个变量的结构,例如是整数型变量还是浮点小数型变量,小数位数取多少合适,变量取值是否代表某种分类,需要如何显示等等;在Step2中,主要考虑根据案例的多少来决定是一个人单独输入所有数据还是多人分别输入然后合成完整的数据。下面我们结合例题具体讲解。

1.1.1 SPSS的数据文件结构

在本例中,我们主要考虑三个变量,分别是投保人的性别、年龄和发生的交通事故次数。其中性别是一个分类变量,它只有男、女两个值;对于年龄,是一个整数型变量;而交通事故次数也是一个整数型变量。以上就是对变量的考虑。对于案例,由于总共有500个案例,单独输入工作量过大,因此可以考虑分别录入再进行合并。 接下来我们就在SPSS中定义变量的结构。图1-1的软件操作界面左下角有两个类似Excel工作表一样的选项卡,分别叫做【Data View】和【Variable View】,其作用和Excel工作表的平行数据表大不相同,有着严格的分工:【Variable View】称为【变量视图】,专门用于定义SPSS变量的结构,而【Data View】称为【数据视图】,用于对案例的录入;换言之,变量视图只用于定义结构,不能用于录入数据,相反数据视图只用于录入数据,不能定义变量结构,对于不同的操作要在不同的视图中完成,这一点请读者务必明确。例如,接下来我们要先定义变量的结构,就应该在【Variable View】中定义。

点击【Variable View】选项卡,进图1-2如下操作界面: 可以看到在此视图中,每一行代表一个变量,本例题定义3个变量,因此有3行,列名称中分别有“Name”、“Type”等,我们已经在图上做出了标示,此处就不赘述了,只是对于重点的几个列进行说明: “Name”菜单表示变量名称,可以用英文字母、数字和下划线给变量命名,也可用中文命名,但是不推荐使用中文作为变量名。
[pic]
• 从SPSS 10.07后,就可以用汉字给变量命名,以前要求变量名长度不超过8个字符,即4个汉字,在SPSS 13.0以后放宽到64个字符,所以可以用汉字命名;但是SPSS的汉字兼容性不太好,以前笔者使用汉字命名时,不止一次分析结果的变量名出现乱码,因此不推荐使用汉字作为变量名,强烈推荐用英文命名变量,变量名标签用汉字说明变量的含义。 [pic] 图1-2 Variable View 操作界面

“Type”表示变量类型,总共有“Numeric”数值型、“Comma”逗号型、“String” 字符串型等八种类型供选择,一般使用数值型就可以了[2];需要特别说明的是,字符串型变量不能用SPSS进行分析,只能起案例名称标注的作用,因此要分析的变量都要转化为数值型变量,例如,本例题中性别这个变量就要转化为取值为1和2的变量,不能直接使用“男”、“女”作为变量值。 “Label”变量名标签的作用非常巨大,由于变量名标签和变量是绑定显示的,在变量分析和显示分析结果时可以一目了然了解变量的含义,对于SPSS的使用者都要养成给变量添加变量名标签的习惯,本例中,对每个变量我们都根据其含义指定了变量名标签,在以后的学习中读者将体会到变量名标签的方便。 “Value”变量值标签也是非常重要的,对于分类变量和定序变量,一般只能取有限的几个值,前面已经了解必须要对其进行编码才能用于SPSS分析,这可以通过编制变量值标签来实现,还可以说明每个取值代表什么含义,例如,本例题性别变量中,我们用1代表“男”,用2代表“女”,这就需要在变量值标签中说明,一旦编制了变量值标签,软件在分析时按照数字进行分析,在显示时按照变量值对应的文字进行显示,这样大大方便对结果的理解。我们通过下述操作编制变量值标签: 点击变量值标签“Value”下对应变量的单元格,出现[pic],点击右边的三个小点,出现如图1-3所示对话框,在Value框中填写“1”,在Label框中填写“男”,说明在SPSS性别变量中取值为1代表是男性,定义好后,点击[pic]添加定义,将在右边的框中显示定义,以后还可以对右边框中定义进行修改(对应[pic]按钮)和删除(对应[pic]按钮)。重复操作可以定义取值为2代表是女性。定义好的标签如图1-4。定义好标签以后,点击[pic],完成变量值标签的定义,以后可以类似定义变量值标签。另外两个变量“年龄”和“交通事故数”由于不是分类变量,不需要编制变量值标签。

[pic] [pic] 图1-3 添加变量值标签的操作 图1-4 添加好的变量值标签

“Measure”变量的尺度,分为三种, ➢ “Scale”称为间隔尺度,说明变量取值有大小之分,并且变量值的差代表差异程度,本例中的“年龄”和“交通事故次数”就属于间隔尺度,有些书籍也称为“定量变量”; ➢ “Ordinal”称为顺序尺度,说明变量取值有大小之分,但是变量值仅表示顺序先后,变量值的差不能代表差异程度,本例中没有顺序尺度变量,但是我们经常接触到的产品分级,职称高低、学历高低都属于顺序尺度变量,有些书籍也称为“定序变量”; ➢ “Nominal”称为名义尺度,说明变量取值没有大小之分,不同变量取值只表示案例属于不同的分类,例如本例中的性别就属于名义尺度,1和2仅仅代表“男”和“女”两个分类,也称为“定类变量”。

[pic] 其实变量的尺度非常好判断,首先判断变量取值有没有代表大小,如果没有,那一定是名义尺度,如果取值代表了大小,再看取值相减有没有意义,如果没有意义,那就是顺序尺度,有意义就是间隔尺度。

根据本例中的变量尺度,我们应该将第一个变量“性别”定义为名义尺度,第二个变量和第三个变量定义为间隔尺度。对于尺度的定义很简单,用鼠标点击“Measure”下变量对应的单元格[pic],点击右侧的箭头打开下拉菜单,进行相应选择就可以了。 通过以上的定义,我们基本定义好了变量结构[3],回到【Data View】,我们看到有三个变量的名称变成了我们刚才定义的变量名,并且变黑了,但是案例的1、2、3还是灰色的,说明虽然定义了变量结构,但还没有输入任何的案例数据。

[pic] 如果读者对变量要求不高,也可以不定义变量直接在【Date View】中输入案例数据,此时会使用缺省变量名“var00001”、“var00002”等来命名变量,但是在以后的分析中我们将发现没有定义变量结构将会有许多不便,想节省时间,结果反而浪费更多时间。所谓“磨刀不误砍柴工”,推荐读者在使用SPSS分析数据时,都先定义变量结构再录入数据。

1.1.2 SPSS的数据录入

现在我们开始变量录入的工作了,如果说变量结构定义是设计整个数据文件的框架和大梁,那么现在的工作就是往框架中添砖加瓦,这是整个数据录入阶段最基础,也是最累人,工作量最大的操作了,但是没有办法,只有一条条案例往数据里敲。这个和任意一个数据录入软件如Excel没有太大差异,只是中间有一些技巧和窍门,是笔者使用的心得,现在和读者共享,读者在使用SPSS中多多总结,也会发现自己的窍门。

数据录入的一些技巧: 1. Copy & Paste 方法,在数据录入过程中,要充分利用Copy & Paste 方法,例如,变量输入中有多个单元格数值相同,则可以输入第一个单元格数值,然后Copy单元格数值,选中第二个单元格,按住Shift键再点最后一个单元格,再点鼠标右键,选择Paste,就可以一次输入多个单元格内容,例如在本例中前250个性别变量取值都是1,则可以如此操作,一次输入所有的1; 2. 如果数据在Excel或者其他数据库文件中,则可以直接在Excel中复制数据内容,再在SPSS中点击第一个单元格,选择Paste,就可以输入数据了,最后别忘了,如果数据没有定义变量结构一定要补充定义变量结构; 3. Word,或者文本格式中,也可以选择复制和粘贴,只不过必须确定全部是数值,否则在粘贴的过程中会出现问题,会使得文本在SPSS中变成缺失值,这是因为SPSS默认变量类型是数值型,对于字符型变量就处理成缺失值了。对于此种情况的处理办法我们在第二节将介绍。

数据编辑的一些技巧 1. 如果在数据录入中想快速找到某一条案例,可以选择Edit菜单→Go to case,输入案例编号,点确定系统就会定位到该案例的位置,如果不知道案例号,只是知道某变量的取值,可以选择Edit菜单→Find,输入要查找的值,一个个查找案例即可; 2. 充分利用变量值标签,此处显示出变量值标签的一个优势,只需选择View菜单→Value labels或者点击快捷按钮上的[pic],此时所有定义了变量值标签的变量输入可以利用下拉菜单完成,点击每个单元格时,右侧会出现箭头,点击会出现下拉菜单,选择下拉菜单的选项就可以完成输入,本例中性别变量就可以按此快速输入;
[pic]用此功能检查变量输入是否出错也很方便,选择Value labels后,有变量值标签的变量所有单元格将显示变量值的说明,例如在本例中,取值为1的单元格中将出现“男”,取值为2的单元格中将出现“女”,如果单元格中不出现“男”或“女”而出现数值,那就说明输入时出错了。

3. 如果数据量较大,此时单独录入容易疲劳,越到后面越容易出错,此时最好在定义好了数据结构以后,将案例分成多份,由多人输入,形成多个数据文件再合并,这样可以提高录入效率,减少录入错误,例如本例就可以将案例数据分成两份,男性案例和女性案例各为一份,由两人分别录入,再进行文件合并,文件合并的操作将在下一小节介绍。

1.1.3 SPSS数据文件的合并

上一小节我们将数据量较大的数据分成两份录入,形成了两个数据文件,比如1-1-1和1-1-2,接下来的问题是如何将两个数据文件的数据合并到一个问卷中,有读者会问,直接把1-1-2的内容复制下来粘贴到1-1-1中不就完了吗?实际上没有这么简单,SPSS是单窗口软件,打开1-1-1文件必须先关闭1-1-2,伴随文件关闭,剪贴板中的内容也不在了,复制粘贴操作必须借助第三方软件,例如Excel;但是随着SPSS版本的升高,SPSS已经从一个单窗口软件变成多窗口软件,这个问题已经不再那么突出,但是我们还是加以介绍,让读者了解文件合并的操作。
[pic]
• 以前SPSS是一个单窗口的软件,不能同时打开两个数据集文件1-1-1和1-1-2,这就使得Copy & Paste数据必须先打开1-1-2,将其内容复制粘贴到Excel中,再打开1-1-1,将Excel中的内容复制粘贴到1-1-1。SPSS17.0已经可以同时打开多个数据集文件了,复制粘贴也可以直接从1-1-2到1-1-1,因此以前的困难现在已经不再存在,这也算是一个进步吧。
[pic]
读到此处,读者也许会觉得,问题已经解决了,不需要再往下说了,但是这其中还有问题,比如,两个文件完全采用了不同的变量顺序,比如1-1-1按照性别、年龄、交通事故次数的顺序输入数据,1-1-2却按照年龄、交通事故次数、性别的顺序输入数据,此时直接复制粘贴就会张冠李戴,行不通了;也许读者会问,那我调整一下变量顺序不就行了,没什么问题啊,在变量不多的情况下,例如本例,确实可以这样操作,但是如果变量很多,要调整顺序也许就是一个非常麻烦的事情了。有没有一个让变量自动“识别”,自动“对齐”的办法呢?办法就是SPSS文件合并。 SPSS的文件合并分为纵向合并和横向合并,因为纵向合并是在已有数据的下面增加案例,所以称为“Add Cases”,同理,横向合并是在已有数据的右边增加变量,因此称为“Add Variables”。到底采用横向合并还是纵向合并是根据待合并文件的结构和数据录入的分工来决定的。

[pic] 如果数据录入分工是每人录入一部分案例(通常的情形),那待合并文件的结构就是全部的变量相同,但是案例不同,此时该使用纵向合并增加案例;如果数据录入分工是每人录入一部分变量(当然这样做效率比较低),那待合并文件的结构就是全部的案例相同,变量不同,当然选横向合并增加变量,很简单吧! 无论是纵向合并还是横向合并,都有一个如何对齐的问题,我们先来介绍纵向合并,既然是纵向增加案例,当然是按照变量对齐,按照如下操作: Step1:打开第一个文件1-1-1, Step2:选择【Data】菜单→【Merge Files】菜单→【Add Cases】菜单
[pic]
图1-5 纵向合并文件选项
出现图1-5对话框该对话框是询问待合并文件是已打开的文件还是磁盘上存储的文件,选择已打开的文件可以在已打开文件列表中直接选取,选择磁盘文件必须指定路径,由于本例中文件1-1-2已经打开,故直接选取,如果没有打开请从第二个选项中指定路径。

Step3:选择文件,点击[pic]按钮
[pic]
图1-6 纵向合并文件选项对话框
出现图1-6对话框,左边框中是为配对的变量,分别来自两个文件,来自当前文件变量名后有“*”,来自打开或者磁盘文件的变量名后有“+”,右边框中是合并后文件的变量,我们通过中间两个按钮将变量从左边选到右边,可以选择两个文件中意义相同的变量,点击“pair”按钮配对生成右边一个变量,表示这两个变量的值对齐生成合并后文件的一个变量,也可以直接选择一个变量,不经过配对,直接点击箭头按钮直接进入合并后文件,此时由于没有变量与之对齐,将会在相应位置出现缺省值;还可以勾选文件来源复选框,将在合并后的文件中新生成一个变量用来记录案例是来自哪个文件。
[pic] 感觉很复杂吧,其实不难,对于两个文件中变量名相同的变量,SPSS会自动配对,比如本例就是自动配对的;所以如果想操作简单,就把两个文件中意义相同的变量取同样的名字吧!当然名字不同也可以配对,例如第一个文件中性别变量名是gender,第二个文件中是sex,选择两个变量点pair,右边会生成一个新变量gender&sex,&前面是第一个文件中的变量名,&后面是第二个文件中的变量名,是不是感觉容易些了?当然,你也可以通过rename按钮将第二个文件的变量名改为gender,那么点配对以后,右边框中只会出现gender这个变量名了。
[pic] 关于缺省值,我们说明如下:变量配对以后不会在合并后的文件中产生缺省值,变量不经过配对直接进入合并后文件,会产生缺省值,如果变量来自第一个文件,那第二个文件没有变量与之对齐,所以第二文件的案例在该变量上是缺省值,反之,第一个文件案例在变量上时缺省值;判断变量有没有配对主要看右边框中变量名后面有没有跟着“*”或者“+”。

Step4:选项选择完成后,点击[pic]按钮,完成文件的纵向合并 由于本例题中所有意义相同的变量的名称都一样,因此变量自动配对对齐,纵向合并的操作非常简单,这从一个方面说明预先定义变量结构的方便性。 下面介绍横向合并,需要说明的是,纵向合并在实际中使用比较多,而横向合并使用很少;这一方面是因为它效率低,另一方面也是因为它在SPSS上的操作比纵向合并复杂,假如我们在进行输入工作分工的时候不是按照案例将输入分工,而是按照变量将输入分工,当然这样分工比较奇怪,因为对于不同案例的输入可以同时进行,而对于不同变量的输入一般不能同时进行,除非有很多个数据的备份,否则在甲输入第一个变量的时候,他必须使用所有的数据,其他输入员就只有等着,效率当然就低了,这个现象在市场调查问卷录入时尤其明显;但是横向合并也有自己的用武之地,比如已有许多变量数据了,后来需要补充输入几个变量,此时可以将要补充的数据形成一个新的文件,再运用横向合并添加到已有文件中,这种情况在市场补充调查中有一些应用。 我们先不管基于什么原因,我们的输入工作确实是按照变量分工的,各录入员也录入数据得到了各自的文件,比如本例中,一个输入员输入性别和年龄变量,另一个输入员输入交通事故次数这个变量,得到两个文件1-1-3和1-1-4,下面将两文件合并。 横向合并是在横向增加变量,当然其对齐的标志只能是案例了,必须清楚每个变量值添加到那个案例后面,为此需要建立一个关键变量,每个案例在此变量上取值都不同,关键变量通常是编号(ID),两个文件都有编号这个关键变量以后,我们就知道5号案例的交通事故次数要加在5号案例的性别和年龄之后,而不会加在2号案例的后面,这样就实现了对齐,不会出错了。

[pic] 纵向合并要求变量和变量能区分,以便清楚性别的值接在性别后面而不是年龄的值后面,这很容易,因为SPSS中不同变量的变量名必须是不同的,变量是自然区别的;横向合并要求案例能区分,这就不那么容易了,因为两个案例完全可以在所有变量上取值都相同,因此,本例中我们需要增加一个编号变量,保证每个案例在编号上取值不同!当然,如果数据本身有编号这个变量,我们就省下力气了。
[pic]
• 当然,用于区分案例的变量不一定是编号,只要是每个案例取值全不相同的变量就可以作为关键变量,所以,关键变量就好像是一个“案例识别器”,运用它就可以把每个案例准确识别出来,就好像给每个案例发一个“身份证”,每个案例的“身份证号”都不相同。
[pic]
当保证两个数据文件中都有关键变量以后,就可以进行横向合并了,其操作如下: Step1:打开第一个文件1-1-3, Step2:选择【Data】菜单→【Merge Files】菜单→【Add Variables】菜单

[pic]
图1-7 合并文件选项 出现图1-7对话框,设置基本相同,此处是选择磁盘文件1-1-4而不是已打开文件。

Step3:选择文件,点击Continue按钮,出现图1-8对话框 对于此选项框,按照图上标示,将关键变量“编号(ID)”选入“Key Variable”框中,并确定案例是按此变量升序排列,右边的“New Active Dataset”框中是合并后新文件中将出现的变量,左边的“Excluded Variables”框中是剔除的变量,将不会出现在新文件中,选中一个变量,点击中间箭头按钮,就可以将变量从一个框移到另一个框,这样就可以决定新文件中将出现哪些变量了,例如,本例中,新文件中将会有性别、年龄和交通事故次数,当然,还有关键变量“编号”。

[pic]
图1-8 横向合并选项框

Step4:选项选择完成后,点击[pic]按钮,完成文件的横向合并[4]
[pic] 感觉横向合并比纵向合并更难了,事实确实如此,横向合并的关键是选择关键变量(Key Variable),关键变量找好了就成功了一半,然后再将需要在新文件中出现的变量选入“New Active Dataset”就大功告成,可以直接点OK了,这个讲解不太难了吧。

现在我们已经能够建立SPSS数据文件的变量结构,并通过键盘输入数据了,如果输入工作量太大,还可以进行分工后运用文件合并功能高效的生成文件;但是在数据分析中,数据用SPSS格式保存的太少了,接下来的一节将介绍如何利用SPSS将已有的其他格式文件转化为SPSS格式。

1.2 从其他文件中导入数据建立SPSS数据文件

SPSS不仅可以自己建立数据文件,还可以将其他应用程序生成的数据文件转化为SPSS的数据文件,SPSS良好的兼容性也是其广泛应用的基础;我们从互联网上,数据库中,或者其他数据处理软件上得到的数据,都能够方便的转化为SPSS数据文件进行分析处理,SPSS不能处理的数据文件是很少的。由于数据文件主要以三种形式存储:应用软件数据文件形式、数据库文件形式还有文本形式,下面我们就分小节对这三种形式的文件分别说明。

1.2.1 从电子表格文件中读入数据

随着MS Excel广泛用于办公和简单数据处理,电子表格文件(后缀名为.xls)成为非常常见的一类数据文件,对于小型或者零散的数据,多数用电子表格文件记录;另外,《中国统计年鉴》以及一些省市的年鉴数据,也是用电子表格文件发布的,因此,掌握了电子表格文件转化为SPSS数据文件的方法,无形中我们的数据来源就丰富了许多。下面通过一个具体的例子让大家了解转化的过程。
例1-2 在随书的光盘中,有一个电子表格文件1-2.xls,记录了一些数据,要求把它转化为SPSS数据文件。 由于SPSS能够直接打开电子表格文件,因此,转化的过程可以归纳为三步: Step1:选择【File】菜单→【Open】菜单→【Data】 打开电子表格文件,或者直接点击快捷按钮[pic],进入如图1-9打开文件对话框,按照图上表示,点击打开类型下拉菜单,选择Excel文件类型,电子表格文件1-2将会出现,再选中此文件,点[pic],出现如图1-10对话框,该对话框询问是否要从第一行读取变量名,以及读取变量的范围,点击复选框,其他选项用默认值,点[pic],将数据读入到SPSS;

[pic] [pic] 图1-9 打开文件对话框 图1-10 读取变量对话框 Step2. 处理缺失值(如果出现缺失值)或者字符变量的值 数据读入以后,我们看到变量已经有变量名了,但是有两个变量取值是字符型,分别是“Ptid”变量和“Clinic”变量,通过查看变量,我们了解了前一个变量是类似编号的编号,可以保持字符型,但是后一变量是表示案例来自那个诊疗科的类别数据,因此要对此变量进行重新编码,将A、B、C、D对应编码为1、2、3、4,将该变量转化为数值型。 Step3. 定义变量结构 为每个变量添加变量名标签,为“Clinic”和“Sex”变量添加变量值标签,定义好变量结构。正确的变量结构如图1-11所示
[pic]
图1-11 变量结构示例图
这样,数据就导入完毕,可以将数据保存为SPSS数据文件了(见光盘1-2.sav)。
SPSS从其他的应用软件(如SAS)中读取文件操作类似,这里就不再赘述了,留作读者练习。

1.2.2 从数据库文件中读入数据

数据库文件是另外一种常用的数据存储格式文件,从专业数据库中得到的数据大多采用此种格式存储,现今使用越来越多的数据仓库,从中获取的数据也多是用数据库文件格式存储的;因此,掌握从数据库文件中读入数据对于扩展SPSS数据源是非常重要的。下面通过一个例子说明如何读取:
例1-3 随书光盘中有一个名为1-3.dbf的数据库文件,记录了2007年7月-2009年6月全国经济一致指数和部分企业家信心指数[5],请将其读入SPSS中并定义变量结构。 从数据库文件中读取数据类似于从电子表格中读取数据,大体也分为三步(和上面相同,此处不列出): Step1:选择【File】菜单→【Open】菜单→【Data】 出现如图1-9所示打开文件对话框,点击打开类型下拉菜单,选择数据库格式“.dbf”,选择文件“1-3.dbf”点[pic],将数据读入SPSS; Step2:对数据集文件进行必要的修改 如图1-12可以看到,读入的数据不很规范,因此需要对数据文件进行整理,将中文变量名改成英文,去掉多余的变量“D_R”,将变量名“n1”改为“yearmon”,表示年月,对数据也进行整理,去掉第一个无效案例。
[pic]
图1-12 数据库文件的读入数据结构 Step3:定义变量结构 除“yearmon”保持不变,其余变量全部转化成数值型,变量长度指定为8,同时添加变量名标签,将变量显示宽度调整为8,变量尺度也全部变成“Scale”。修改好的数据文件保存为SPSS文件(见光盘“1-3.Sav”)。 上面介绍的是比较简便的读取数据库文件的方法,另外SPSS还提供数据库向导的方式读入数据库文件,分为三步: Step1:选择【File】菜单→【Open DataBase】菜单→【New Query】 将看到图1-13所示的数据库向导窗口,看到SPSS提供三种数据库读入向导:dBase、Excel、Access格式,光盘中有1-3.xls的Excel文件,因此我们选择第2种文件格式,因此选择第2个向导选项,点击“Next”;进入一个文件路径对话框,指定路径后点击“Ok”,即进入如图1-14所示的变量选择对话框; Step2:选择变量、案例、变量名等相关设置 图1-14左边变量框列出Excel工作表中的所有变量,可以将变量选到右边的变量框中,右边的变量框中是将被读入SPSS文件的变量,中间按钮用于选择变量,右边的两个按钮用于调整变量的顺序,选择好变量后,点击“Next”,进入案例选择对话框,如图1-15所示; 一般说来都会读取全部案例,所以这个对话框将不会有任何操作,直接点“Next”进入下一对话框。

[pic] 读者可以通过指定条件只读取满足条件的案例,但是我们并不推荐这样做,一方面是因为此处指定条件比较麻烦,必须熟悉数据库的操作,另一方面也因为读取全部案例以后在SPSS中进行选取更加方便。

图1-16是变量名称、变量类型和变量显示长度定义对话框,将名称改为英文,将变量类型修改为数值型,再将变量长度修改为8个字符,点击“Next”进入最后一个对话框,显示数据库选择语法,不用理会,直接点击“Finish”完成设置,读入数据。

Step3:定义变量结构 为每个变量添加变量名标签,需要的话添加变量值标签,指定变量类型,这些操作和上面类似,就不再赘述了。

[pic] [pic] 图1-13 数据库向导窗口 图1-14 变量选择对话框
[pic] [pic]
图1-15 案例选择对话框 图1-16 变量名、变量类型、长度等定义对话框

1.2.3 从文本文件中读入数据

文本格式文件是另外一大类数据存储格式,由于文本文件容量小,便于存储和传输,我们从互联网下载的数据,就有很多是用文本格式存储的;国外的很多研究机构和调查公司发布数据,也偏爱文本格式,因此,我们必须掌握将文本格式数据导入SPSS中,才能将数据文件的建立掌握的更全面。 SPSS能够导入两种格式的文本文件,分别是后缀名为.txt和.dat的文件,从文本文件向SPSS导入数据相对比较复杂,我们也为读者准备了一个例子,用这个例子一步步讲解数据导入的过程。
例1-4 在随书附赠的光盘中,有一个1-4.txt的文件,记录了一些个人信息数据,请将其读入SPSS中形成数据文件。 Step1:选择【File】菜单→【Read Text Data】 进入如图1-9的打开文件对话框,然后在文件类型下拉菜单中选择“Text”,在文件列表中选中1-4.txt文件,点击“Open”,进入文本文件向导。

[pic] 读者也可以选【File】菜单→【Open】→【Data】进入打开文件对话框,然后在文件类型下拉菜单中选择文本文件(后缀名为.txt),点击[pic],同样会进入文本文件向导流程。 [pic] [pic] 图1-17 文本导入对话框1 图1-18 文本导入对话框2 Step2:完成文本导入设置 在图1-17的中,主要询问是否已有一个导入模式用于导入文本,由于是第一次导入数据,没有模式,所以选“No”,点击“Next”进入图1-13文本导入对话框2。 在图1-18中,主要询问两个问题,问题1询问文本中变量的组织形式,一般选择第1选项“由分隔符将变量分开”,第2选项“变量被指定固定宽度”,只有在变量数据没有分开是才选择。问题2询问第一行是否是变量名,通过观察下面的数据内容,可以确定第一行是变量名,因此,问题2选“Yes”。 [pic] [pic] 图1-19 文本导入对话框3 图1-20 文本导入对话框4 进入图1-19,主要询问3个问题,问题1,数据从哪一行开始,如果前面选了第一行是变量名,数据就从第二行开始,此处用默认值就可以;问题2,案例是如何安排的,选项1“每行表示1个案例”适用于案例分行放置的数据,选项2“每个案例由X个变量值组成”,其中X在后面的框中选择,适用于案例不分行连续放置的数据;问题3,读取案例的数目,选项1“案例全部读取”,选项2“读取前X个案例”,选项3“随机读取X%的案例”,在本例中,数据按行放置,要全部读取,因此问题2和3都选1选项。 进入图1-20,选择变量之间的分隔符,分隔符有跳格、空格、逗号、分号和自定义符号,可以复选,分割符选择正确以后下方的数据会自动分开对齐变量,如果没有分开对齐变量,说明分隔符没选对。 后面还有一些对话框,都不重要了,直接一直点“Next”,然后点“Finish”完成文件读取。 Step3:定义变量结构 千万不要忘记定义变量结构,指定变量类型,添加必要的变量名标签和变量值标签,数据文件建立过程结束将文件保存成SPSS数据文件(见光盘1-4.sav)。

[pic] 最后一个对话框,询问是否将读取文件的设置存储为固定的模式,以便下次读取文件时使用,如果是一次读取多个文件,推荐保存模型,再次读取时就可以在对话框1直接载入模式直接读取,提高效率。

【本章知识点】

数据文件的建立是SPSS分析的基础,而且为了以后的使用和分析方便,在建立数据文件时尽量做到变量清楚,结构完善,特别注意添加变量名标签和变量值标签。 数据文件的打开和数据导入是从二手数据获得SPSS数据集的重要途径,读者应该熟练掌握直接打开Excel文件、数据库文件和SAS数据集文件的操作;清楚利用文本向导和数据库向导从相应格式文件中读入数据的步骤,并掌握其SPSS操作。 数据合并和提高SPSS数据录入效率的有效途径,读者应该仔细区别纵向合并和横向合并从应用条件、对齐标准、SPSS操作等诸多方面的不同,并能够根据实际情况的需要灵活的运用两种文件合并的技术,迅速完整的输入数据。

【思考和练习】
1. SPSS文件和普通的数据文件如Ecxel文件和数据库文件有什么不同,其特点是什么?

2. SPSS对一手数据和二手数据的录入上有没有不同?如何处理这两类数据?

3. 随机附赠的光盘中有一个bp5.sas7bdat的SAS数据集文件,请利用SPSS打开文件的功能打开此文件,并为其定义适当的变量结构。

4. 对照书籍利用1-4.txt文件重新熟悉文本导入的操作,并自行寻找一个文本格式的数据文件练习数据导入的操作。

5. 对照数据利用1-3.xls文件熟悉数据库文件导入的操作,并自行寻找一个数据库文件练习数据导入操作。
[pic]
----------------------- [1]为节省篇幅,表中仅列出部分投保人案例,完整数据请见光盘中的数据集1-1 [2]关于变量类型的说明,可以参看薛薇编著,《统计分析与SPSS应用》,北京人民大学出版社 [3]关于变量其他属性的定义和说明,请参看张文彤《SPSS11统计分析教程》,北京希望电子出版社。 [4]关于案例来源单选框,解释起来很复杂,而且用处不大,就用默认选项就好了,有兴趣读者可以参看相关书籍。 [5]数据来源:中经网数据库

-----------------------
本篇要点导读:
第1章 SPSS数据的录入 数据录入的一般步骤,数据结构的定义,文件合并,文本数据的导入;
第2章 数据文件的操作和预处理 【Data】菜单中对变量和案例的操作,【Transform】菜单中计数和分类赋值的操作。

本篇说明:
1. 本篇重点说明数据录入和文件整理的整个过程,以及过程中特别需要读者注意的问题,对于SPSS操作简明扼要,没有对每一个选项进行详细说明,只是配合例题针对常用和重点选项进行说明,如读者想了解详细说明请查阅相关书籍,本书会给出标示。在以后的章节中我们也会遵循这一原则,不再特别说明;
2. 如果读者是有一定的SPSS使用基础,了解SPSS的一些基本操作,对数据录入和预处理比较清楚,可以简略浏览本篇,重点了解数据录入的一般流程和预处理中注意的问题。也可直接略过本篇从第二篇开始学习;
3. 如果读者是SPSS初学者,由于本篇在软件操作上的介绍比较简略,请初学者在学习此篇的时候一定遵循我们的例题操作并注意图例标示,必要时查阅书中列出的相关参考书籍,并完成课后两道以上的习题操作,务求掌握此篇内容,为以后SPSS软件学习奠定基础。

数据视图和变量视图

总共有多少个变量,其中可见的有多少个变量

案例1、案例2…

变量

变量名标签

变量尺度

对齐方式

变量缺省值

变量显示宽度

变量类型

变量值标签

小数位数

变量位数

变量名

添加定义

取值的实际含义,文字

在SPSS数据文件中的取值,数字

选择文件后点击此按钮

从指定路径选择一个磁盘文件

选择一个已打开的文件

重命名按钮

未配对变量框

文件来源复选框

变量不配对进入合并后文件的按钮

合并以后文件中的变量

配对按钮

案例来源单选框

然后选择关键变量-ID

首先勾选此项

最后点此确定关键变量

选择文件类型下拉菜单中的Excel文件类型

调整变量顺序按钮

选择变量按钮

选择Excel Files后点此按钮

变量名称中文改成英文

变量长度改成8个字符

----------------------- 『 16 』

Similar Documents

Free Essay

Officers

...PROBATION AND PAROLE What are the job functions of a parole officer? A parole officer monitiors the offender to ensure that he is following each condition of release. They may also perform random drug testing, monitor employment history and performance, meet weekly or bimonthly with the offender and his family, and present evidence to the judge in the event a condition is broken. What are the pros and cons of the position? The pros are income, foot in the door, productivity, respect, confidence, healthcare. The cons are lower wages, no future, multiple jobs, limited time for job- hunting. What are their recommendations for entering that field? Prospective parole officers normally receive a high school diploma or G.E.D as the first step toward their career objectives, most government agencies require parole officers to have a bachelor’s degree. Are you interested in this career? Why or why not? Yes I am interested in this career because I want to be a probation or a parole officer one day and that’s why I’m taking criminal justice class. I want to put the bad guys behind bars, so they can learn their lessons and you got some that follow the rules and we got some that don’t but we all got somewhere they will follower the rules at and that is prison or jail. Some probation officers try to look out for some of these hard head boys and girls but they don’t believe nothing until they behind them bars and then they crying like babies… that’s why I teach my kids hardhead leave a...

Words: 333 - Pages: 2

Premium Essay

Police Officers

...and Safety Issues of Police Officers in Canada, the United States and Europe: A Review Essay © Jennifer R. L. Parsons June, 2004 2 Introduction Police officers play a pivotal role in North American and European societies. They are involved in many aspects of North American and European life. Officers’ involvement ranges from general, daily, proactive patrol activities to specific criminal activities such as narcotic investigations. Because there is such a wide range of activities involved in police work, there are many health and safety issues surrounding policing as an occupation. Police officers may be exposed to different health and safety risks in their occupation. For example, police officers are at risk of assault and homicide; the dynamics of policing as an occupation creates opportunities for them to experience many psychosocial hazards such as stress, suicide, sexual harassment, and discrimination. It is important that research be completed on the health and safety issues of police officers in order to identify hazards and identify ways to reduce risk. The failure to identify and solve health and safety concerns of officers has potentially serious consequences for the health and well being of officers and their families. These consequences can include depression, divorce, suicide, and disease. Not addressing the health and safety issues associated with policing may also impact the general public. For example, if an officer is stressed or fatigued he/she...

Words: 19151 - Pages: 77

Free Essay

Police Officers

...the requirements for the police officer for the local agency have changed over the years. Forty to fifty years ago, all police officer were strong male, majority white, and only a high school diploma. Not until the 70’s, African American and Hispanic were allowed to be a police officer and even then females were allowed. Today the requirement has changed to become a police officer in the city of Southfield, Michigan there are assortments of requirements that they must pass before they will accept you. The basic requirement before you can be chosen for a police officer; you must meet the all of the Michigan Commission on Law Enforcement Standards (MCOLES), which are reading and writing test, physical fitness performance examination, and the psychological examination. The Michigan Commission on Law Enforcement Standards is broken down in these sub-categories of age, education, physical fitness and integrity, and citizenship requirement. In the State of Michigan, the minimum age is 18 years old, must have a high school diploma and a background check. For example they will fingerprint you to make sure that you have not committed crimes in different states. You will be require to be a US citizen, no felony records or even an expunged record this include a good moral character or good choice of judgment. Required to have a good driving record and it must be valid in the state you reside in. Second basic requirement is the physical fitness and integrity. You cannot have a mental...

Words: 334 - Pages: 2

Premium Essay

Probation Officer Research Paper

...the probation officer because the probation officers duties are is that the person don't have to go to jail, but they have to work with a probation officer to protect against new crimes. A probation officer meets with these people periodically, as assigned by the court. The officer gets updates on their activities and addresses any illegal or against the rules of the court behaviors which means they do the most in communication and collaboration. When it comes to police officers and technology during a crime scene that which includes drops of blood, a hammer, shoeprints, and a handprint not much technology is needed. However, new technologies...

Words: 1294 - Pages: 6

Premium Essay

Officer Palafox Case Study: Investigative

...Officer Palafox and I started the shift by going over the expectations for the weekend. We discussed the areas which he most needs improvement. They included; • Officer safety • Report writing • Investigative skills Officer Palafox conducted a traffic enforcement stop in the area of Mission Street and East Cavour Street. He transmitted the to stop by the following: “ C255 1186 Mission/ East Cavour”… “vehicle plate”… “Description”, which the description being broadcast after he was already making his approach to the driver. This has been a continuing problem for Officer Palafox. Officer Palafox conducted a traffic enforcement stop at Mission Street and Bepler Street. County Communications did not hear his call sign and asked him to re identify...

Words: 1056 - Pages: 5

Premium Essay

Noncommissioned Officer Position

...While serving as a noncommissioned officer in the United States Army, I was assigned to the S3 Planning & Operations Section for an intelligence battalion. My regularly assigned responsibility was being the Assistant Battalion Training Noncommissioned Officer. However, my duties included the gathering of intelligence from the field, communicating vital information to my superiors, and working within a Tactical Operations Center (TOC) environment. A TOC is a where the commander of a unit can obtain and disseminate vital, real-time intelligence and information. This environment honed my relative competencies and prepared me for my future exploits working in an Emergency Operations Center (EOC). Also, during my tenure as a soldier, I was assigned...

Words: 267 - Pages: 2

Premium Essay

Correctional Officer

...I am the Lead Supervisor of Correctional Officers I and II by making general inspections to see that rules and regulations are being served, and that institutional programs are being carried out in a satisfactory manner. I was selected through my ability to research and interpret policies, procedures and regulatory guidance for the application of the "Big Picture". This coupled with my knowledge of management programs, training, and ability to identify and resolve problems I accomplish the following: Oversee sub-units in the facility performing work in specific areas, such as: compliance monitoring, security, commissary, living units, etc. I am the responsible Officer for the operation of the institution on a particular shift when administrative...

Words: 410 - Pages: 2

Free Essay

Attributes of a Police Officer

...Police Officer -------------------------------------------------------------------------------- Courteous Every member of the Police Force is a guardian and servant of the public. He or she is there to help and protect members of the general public and treat all persons with unfailing patience and courtesy, regardless of their social position, and answer all their questions with civility, no matter how trivial that they may seem to be. Saying good morning, thank you, please, would you mind, excuse me, I beg your pardon, cost nothing but leaves a positive and professional impression on the public. Tact The approach of a police officer has a great effect on the attitude of the public. That is why the use of tact and persuasion instead of force is encouraged. You will find that members of the public will comply with direction more willingly when they understand the situation or the event that took place. Insisting on the right of your authority instead of using tact will run you in the risk of having your authority challenged. Confidence It is very important that you have confidence in yourself and know exactly what you intend to do. A true knowledge and understating of your powers is needed. As long as you use your powers properly and fairly, you will have no fear of any consequences. Always make sure that you understand your orders properly before performing your duties. If you do not understand, you cannot expect to direct the public properly. Temper ...

Words: 892 - Pages: 4

Free Essay

Officer Selection Paper

...the topic as we will be discussing the selection process of various levels of police such as local, state or federal officer and also we will include the various training programs through which the officers of each level goes before they are employed as officer. So as we are aware of the fact that police officers play most important role in maintaining disciplines and also they are the one who are most reliable for fighting with various types of crimes and criminals. So as it is very clear that the job of a police officer is a very hard one because they do face very tough problems while doing their job, so this is the reason why police officers do need to go through a very tough training and also various selection processes so that they do not face any difficulty while handling various criminals and therefore can perform their job very well. As there are certain levels of police officers like local, state and federal police officers and also of them go through various training programs before they are appointed as police officers. So let us discuss the selection process of a local, state, federal police officer, there are some requirements which are checked in the selection process. These are:- 1) Health- It is very important to know the physical and mental condition of a officer before selecting because it is very important to make sure that police officer is of sound mind and is also physically very strong to handle any bad situations. 2) Integrity / Conduct - It means...

Words: 1068 - Pages: 5

Premium Essay

Personal Narrative: A Career As A Law Enforcement Officer

...In the media, you always hear about law enforcement officer taking advantage of their positions. I was certainly curious to ask Mrs. Sacaza about this matter. When asked if there was ever a time she used her job title to her advantage she said “I did it all the time when it came to getting discounts that came with being an officer and if I was pulled over.” I then asked if she witnessed another officer using his/her title to their advantage, such as using sirens to run red lights. There was a long pause before she answered, but she finally said “I have seen officer do that but I never did it.” She then went on to say “I always saw my colleagues pulling over females to give their numbers.” I was very to see if she would admit using the system for her personal us. It was a question I already knew that answer to because her daughter was one of my best friends. I asked the question and she immediately began laughing, she explained that once her daughter dated a guy that seemed shady, and she used the system to look him up. She also admits that she uses they system to profile anyone that seem shady in her personal life....

Words: 506 - Pages: 3

Premium Essay

Noncommissioned Officer Research Paper

...history of the Noncommissioned Officer. A history that is full of discipline, gallantry, honor, selfless service, and heroism. Post-Revolutionary War, the duties and responsibilities of a noncommissioned officer had very little standardization which was soon to change. In 1778, during the winter at Valley Forge standardization was about to be met with the publication of Inspector General Friedrich Von Steuben’s Regulations for the Order and Discipline of the Troops of the United States (printed 1779). Referred to as the Blue Book, it outlined the duties and responsibilities of noncommissioned officers At the time the Blue Book outlined the five separate ranks of noncommissioned...

Words: 2064 - Pages: 9

Premium Essay

Warrant Officer Research Paper

...Over the course of my career I have served as a Non-Commissioned Officer (NCO) for more than eight years, and held such leadership positions as Team Leader, Squad Leader, Section Sergeant and Platoon Sergeant. I have been directly in charge of as many as 18 Soldiers and NCOs as well as serving as an instructor at the AIT level as an NCO. I have also served as a Platoon Leader and Company Standardization Officer as a Warrant Officer and I can honestly say that the leadership role of an NCO is not much different than that of a Warrant Officer. As an NCO I was directly tasked with leading, mentoring, training and caring for the Soldiers. As a NCO it was my personal responsibility to ensure that Soldier had a task and purpose, were counseled on their performance, and were properly trained to accomplish their mission on a daily basis. As a Warrant Officer, I provide mentorship to the Soldiers and show them what the standards are, lead them by example and always exemplify a level of...

Words: 550 - Pages: 3

Premium Essay

Becoming A Detroit Police Officer

...There are multiple reason on why I want to become a Detroit Police Officers. To begin with been a Detroit police officers is a privilege in itself to carry a title as such for a city like Detroit. It’s more than just a badge it’s been able to protect, represent and service a city with over 650,000 citizens. It’s been able to arrive at a call and instantly make a family feel safe. It’s coming into work every day not knowing who you might encounter and what the day may hold. It’s been able to encounter different cultures and groups of people on a daily basic. It’s not about giving back for me it’s about been a part of something bigger than myself. It’s about giving my peers hope that a life of crime or doing wrong is not the only way to live...

Words: 390 - Pages: 2

Premium Essay

Essay About Police Officers

...Owen, A. (2004). Keeping You Safe A Book About Police Officers. Mankato, Minn: Capstone imprint. A Day in the life of a Police officer you see police officers on TV, riding in cars, riding bicycles and, others riding horses. All of them work hard to keep your neighborhood safe. How a police officer spends his day working has much to do with his assignments and, the agency where he works. Police officers can be assigned to uniformed patrol, traffic, investigations (detectives), training, a school resource program, or supervisory duties. I'll focus on the role most people associate with policing, that a uniformed patrol officer does. The day starts out with roll call, twelve minutes before our actual shift start time. Most days are full of typical calls for service. We refer to dispatched calls as “hitches.” We either get immediately dispatched to calls or we begin to patrol until we are dispatched to a call for service or hitch. It is up to the individual officer whether to make lots of traffic stops or stop in at local businesses and say “hello.” Being visible by patrolling areas which are more plagued by crime can, of course, help deter crime in those areas. Bridget, H. (2013) Lets Meet a Doctor. Minneapolis, MN: Millbrook Press What does a Doctor do? A Doctor helps children when they are...

Words: 939 - Pages: 4

Premium Essay

Media's Influence On Police Officers

...have for police officers today. Is media to blame for the hate?Is the media unfairly targeting police officers ? . Making it seem like they are killing machines, and burial. Rather than people who protect the community. Today, the media has attacked law enforcement by saying that all they do is racial profile,not doing their jobs right, and that the police uses excessive force on the innocent . On the other hand. The law enforcement has been able to prove that wrong otherwise.For example, in many cases, a suspect is approached by police and he or she is unwilling to comply...

Words: 996 - Pages: 4