Showing posts with label SPSS. Show all posts
Showing posts with label SPSS. Show all posts

Syntax Comments in SPSS

There two way to write comments in SPSS: the non executed line and the in-line comment.

The first, the non executed line, look like this:

* reliability of measures.
RELIABILITY
/VARIABLES=it1 it2 it3
/SCALE('ALL VARIABLES') ALL
/MODEL=ALPHA
/STATISTICS=DESCRIPTIVE SCALE
/SUMMARY=TOTAL.

This is ok for making titles before sectionsn out ot a syntax; or to cancel out commands. like in the following example.

if(it1 = 1) dummy = 1 .
if(it1 = 2) dummy = 0 .
*if(it1 = 3) dummy = 1 .
execute .

On the other hand, the inline comments, serve the purpose of including a comment within a line of commands, like this.

if(it1 = 1) dummy = 1 .
if(it1 = 2) dummy = 0 .
if(it1 = 3) dummy = 1 . /* discuss this option in the research meeting */ 
execute .

 

via

http://www.dummies.com/how-to/content/spss-syntax-language-comments.html

HOW TO run a frequencies in SPSS / SAS

In SPSS:

GET

     SAS DATA='D:\DATA\data.sas7bdat'.
DATASET NAME CC WINDOW=FRONT.

FREQ var .

In SAS

Libname data 'd:\data\sas\';
options fmtsearch=(data);

proc freq data= data.example;
table var;
run;

In SAS, it can require more commands due to more speifications are being made, such as: creating a library, specifying where is the format of the data, and then asking for the frequency .

Aditionally,  one can ask for the same table, including the missing values:

proc freq data= data.example;
table var/ missing;
run;

Or can ask for the same table in an html format to be exported:

ods html;
proc freq data=ccalum.ccalumnos;
table i2/ missing;
run;
ods html close;

HOW TO: open a database in SAS / SPSS:

Similarly to SPSS one can call a database and ask for full description of the content.

In the case of SPSS one could do:

GET
     SAS DATA='D:\DATA\data.sas7bdat'.
DATASET NAME CC WINDOW=FRONT.

DISPLAY DICTIONARY .

 

As where in the case of SAS we chould do:

options nocenter;
proc contents position data=' D:\DATA\data';
 run;

'options noncenter' is just giving a format for how the output will look (asking for it be justifyed to the left of the screen).  Only the second syntax line, is mimicing the 'display dictionary', in order to display the contents of the database.

'run' is the simil to execute in the case of spss, or just the ';' in the case of mplus.

 

How to write variables labels with ' in between (don'ts; I'll; ain't and so forth)

In SPSS, to document a dataset VARIABLE LABEL command is used.In this respect, for each variable the item in use could be entered, to keep the record for each data field. In other scenarios would be the name of a construct or scale; or a short description for the variable located in data field.
If our item is written in the following format:
I didn't let myself have thoughts related to it. [1]
Lets supposed the answer for this item will be recorded in IES15. Then, the following syntax would apply to build up the corresponding label:
VARIABLE LABELS IES15 'I didn't let myself have thoughts related to it.' .
 However, the result would be following

To avoid this bug or unintended result, the syntax can be corrected using " in the limits of the item label:
VARIABLE LABELS IES15  " I didn't let myself have thoughts related to it." .
obtaining:




[1] REFERENCE for the item in the example: 
Horowitz, M., Wilner, N., & Alvarez, W. (1979). Impact of Event Scale: a measure of subjective stress. Psychosomatic Medicine, 41(3), 209 -218.

Listwise warning with ANOVA and other analysis, for several DV in a hit

I Just find out a not so obvious assumption in SPSS.


When you need to estimate several ANOVA, ROC curve, even maybe with T TEST, and you replace in the depedent variable section for more than one variable, like this:

UNIANOVA
VARD1 VARD2 BY group
  /METHOD=SSTYPE(3)
  /INTERCEPT=INCLUDE
  /POSTHOC=group(BONFERRONI)
  /PLOT=PROFILE(group)
  /EMMEANS=TABLES(OVERALL)
  /EMMEANS=TABLES(group) COMPARE ADJ(BONFERRONI)
  /PRINT=ETASQ HOMOGENEITY DESCRIPTIVE
  /CRITERIA=ALPHA(.05)
  /DESIGN=group.

What SPSS would do regarding the listwise deletion cases is to restrict your analizable sample data, to the common cases which have valid values for the 3 variables as a whole. All in all, this means all the estimates are restricted to this maybe smaller data sample of the overall data available to estimate all the parameters.


If you have full data (no missing cases), or just a few missing data, is not going to cause too much of trouble. Maybe just a small deviation for the parameters which would not affect decisions over scale selection, for example. Nevertheless, if you got at least one variable of them with a considerable loss of data (lets say 50% valid cases for the overall data set), all the estimates will be calculated using this restricted list wise cases instead of the full available data for each pair of variables (vard1 with group & vard2 with group) biasing seriously the parameter estimates (F, n2p, for this case).


So be careful.


But if you still need to get the n2p for each pair of variables for a set of 36 dependent variables for example, employing cross reference 'email list' from WORD, you can automatize the production of a proper list of SPSS syntax for each pair, avoiding to write down 36 sets of code line.


UNIANOVA
<<insert field here>> BY group
  /METHOD=SSTYPE(3)
  /INTERCEPT=INCLUDE
  /POSTHOC=group(BONFERRONI)
  /PLOT=PROFILE(group)
  /EMMEANS=TABLES(OVERALL)
  /EMMEANS=TABLES(group) COMPARE ADJ(BONFERRONI)
  /PRINT=ETASQ HOMOGENEITY DESCRIPTIVE
  /CRITERIA=ALPHA(.05)
  /DESIGN=group.

===> edit documents:


UNIANOVA
vard1 BY group
  /METHOD=SSTYPE(3)
  /INTERCEPT=INCLUDE
  /POSTHOC=group(BONFERRONI)
  /PLOT=PROFILE(group)
  /EMMEANS=TABLES(OVERALL)
  /EMMEANS=TABLES(group) COMPARE ADJ(BONFERRONI)
  /PRINT=ETASQ HOMOGENEITY DESCRIPTIVE
  /CRITERIA=ALPHA(.05)
  /DESIGN=group.




UNIANOVA
vard2 BY group
  /METHOD=SSTYPE(3)
  /INTERCEPT=INCLUDE
  /POSTHOC=group(BONFERRONI)
  /PLOT=PROFILE(group)
  /EMMEANS=TABLES(OVERALL)
  /EMMEANS=TABLES(group) COMPARE ADJ(BONFERRONI)
  /PRINT=ETASQ HOMOGENEITY DESCRIPTIVE
  /CRITERIA=ALPHA(.05)
  /DESIGN=group.






I'll try to re-write this post with a proper example, in a few days.






Cómo calcular el RUT en SPSS, mediante syntax


El código verificador del Rol Único Tributario (RUT), emplea un algoritmo de verificación llamado módulo 11; o más concretamente el ‘IBM® Modulus 11 Algorithm’. Este algoritmo, basado en la aritmética modular (Paar, Pelzl, & Preneel, 2010)[1], emplea la propiedad del módulo 11 para validar la secuencia de 7 a 8 digitos del rut.

El módulo 11 de un número determinado consiste en el resto de su división por 11. Por ejemplo, el módulo 11 de 27, es 5. Esto es porque 27 es expresable como 2*11 más 5 (27=2*11+5), donde 5 es el resto de la división de 27 por 11. Los RUT validos se encuentran construidos en base a la secuencia del módulo 11. Todos los RUT validos cumplen la condición de que, el código verificador más el módulo 11 de la de la sumatoria de todos los números de RUT multiplicados por el coeficiente de posición de cada número que compone la secuencia del RUT son iguales a 11.



Para el caso de los códigos verificadores 0 y K del RUT corresponden al verificador 11 y 10 para la secuencia del RUT Chileno. En la tabla 51, se muestra el ejemplo de cálculo de código verificador para 5 RUT diferentes.

He aquí el syntax en SPSS

******************************************************************************************************************************* SEPARAR RUT y DV en dos variables.

*DADA una variable TEXTO 'RUTDV' en la cual se encuentren registrados todos los rut, con el siguiente formato
[RUT]-[DV], ó '12345678-k'; este syntax puede crear el RUT y el DV por separado .

********************************************************************** CREA espacios para variables texto.


NUMERIC blank (F1) .
STRING RUT (a20) .
STRING DV (a1) .

COMPUTE blank = INDEX(RUTDV,'-' ).
EXECUTE .
COMPUTE RUT = SUBSTR(RUTDV,1,blank-1 ).
EXECUTE .
COMPUTE DV = SUBSTR(RUTDV,blank+1 ).
EXECUTE .


********************************************************************** CONVIERTE rut extraido en numerico .

ALTER TYPE RUT (F8) .


******************************************************************************************************************************* CALCULAR los DV a partir del RUT .

COMPUTE RUTtext = RUT .
EXECUTE .

ALTER TYPE RUTtext (A8) .

STRING i8 i7 i6 i5 i4 i3 i2 i1 (A1) .
EXECUTE .

COMPUTE i8 = SUBSTR(RUTtext,1,1).
COMPUTE i7 = SUBSTR(RUTtext,2,1).
COMPUTE i6 = SUBSTR(RUTtext,3,1).
COMPUTE i5 = SUBSTR(RUTtext,4,1).
COMPUTE i4 = SUBSTR(RUTtext,5,1).
COMPUTE i3 = SUBSTR(RUTtext,6,1).
COMPUTE i2 = SUBSTR(RUTtext,7,1).
COMPUTE i1 = SUBSTR(RUTtext,8,1).
EXECUTE .

RECODE
i8 i7 i6 i5 i4 i3 i2 i1
(''=0)
('0'=0)
('1'=1)
('2'=2)
('3'=3)
('4'=4)
('5'=5)
('6'=6)
('7'=7)
('8'=8)
('9'=9) INTO
n8 n7 n6 n5 n4 n3 n2 n1 .
EXECUTE .

COMPUTE RUTtot = n8*3+n7*2+n6*7+n5*6+n4*5+n3*4+n2*3+n1*2 .
EXECUTE .

COMPUTE DVc = 11 - mod(RUTtot,11) .
EXECUTE .

ALTER TYPE DVc (F2) .

STRING DVrut (a1) .

IF(DVc = 11) DVrut = '0' .
IF(DVc = 10) DVrut = 'K' .
IF(DVc = 9) DVrut = '9' .
IF(DVc = 8) DVrut = '8' .
IF(DVc = 7) DVrut = '7' .
IF(DVc = 6) DVrut = '6' .
IF(DVc = 5) DVrut = '5' .
IF(DVc = 4) DVrut = '4' .
IF(DVc = 3) DVrut = '3' .
IF(DVc = 2) DVrut = '2' .
IF(DVc = 1) DVrut = '1' .
EXECUTE .

VARIABLE LABELS DVrut 'DV calculado a partir de RUT numerico' .


Posteenme si tienen comentarios!







[1] Paar, C., Pelzl, J., & Preneel, B. (2010). Understanding Cryptography: A Textbook for Students and Practitioners. Springer.

SPSS matriz de gráficos de una sola variable

Este es solo una idea que fue probada pero tiene algunos reparos practicos de formato.
El tema es como generar una matriz de graficos en spss en base, principalmente, a una variable pero customizado. Estoy pensando en algo como en la siguiente imagen



El problema particular lo planteo del siguiente modo:

Tengo 32 carreras y quiero ver en paneles como se comportan respecto de cierto item. El problema está en que no sé como configurar para decirle a SPSS que agrupe en 8 filas y 4 columnas cada uno de los graficos. Sólo puedo agrupar las 32 carreras en una columna con 32 filas o en una fila con 32 columnas (formato para nada practico como podrán imaginarse)

Lo que se me ocurrio entonces, fue entender primero este "panel de graficos" como una matriz de graficos y asingarle una ubicacion a cada uno en base a su posicion vertical y horizontal. Por ejemplo la carrera de arte y teatro iria en la ubicación fila 1, columna 1 (1,1) y trabajo social en la ubicacion (8,4).

Tomando el problema desde esta perspectiva, compute dos variables, la primera se llamó rowpanel donde le asigne a cada carrera su posición en la fila que le correspondía, la segunda, colpanel, le asigne la columna a cada carrera segun le correspondia. Preferí ordenar las carreras en orden alfabetico, es decir Agronomía en el (1,1) y trabajo social en la posicion (8,4), sin embargo eso es optativo. La escritura sistemática de las formulas fue realizada con excel 2007 y el comando "display dictionary" de spss. La formula para asignar los numeros en spss fue "if(carrera=Valor numerico de la carrera) rowpanel (o colpanel) = valor fila o columna en la matriz grafica"

En fin, realizando todo esto, me demoré muy poco, sin embargo no puedo hacer que cada cuadro tenga el nombre de la carrera a la cual representa el cuadro.

Por lo tanto, al menos hay tres opciones:
a) Buscar si spss tiene este problema resuelto
b) Editar cada uno de los cuadros agregando un "textbox" con las carrera que le corresponde
c) Dejarlo tal cual y solo utilizarlo como una forma de mirar los datos, de manera más panoramica que las 32 columnas (filas)

saludos, espero si tienen la respuesta, la compartan y/o que esta idea les sirva de algo.