Exporting raw data
Exporting involves copying the cleaned and aggregated raw data from the Access database where they are stored, into csv files that can be read into SPSS. The process of exporting raw data is described in general terms in the data processing summary page.
The study data, including admin data, stored in the Access 7yr.accdb database file, have been subject to occasional changes, even after the end of data collection. In earlier years, changes were caused by late returns of parent and teacher booklets, and more recently changes have occasionally been caused by data cleaning or data restructuring changes. If these changes have been made, then the data should be re-exported before a new version of the dataset is created using the SPSS scripts. The data stored in the database tables are exported indirectly, by means of saved "queries" (or views), rather than directly from the tables themselves. Each query selects appropriate columns from the relevant tables, excluding inappropriate data such as verbatim text fields. The queries also modify the format of the data values in some columns, so that they are saved in a format that can easily be read by SPSS; examples are date columns (changed to dd.mm.yyyy format) and true/false columns (changed to 1/0 values). The queries used to export the data are as follows:
Query name | Source of data | Database table(s) involved | Exported file name |
---|---|---|---|
Export Parent1, Export Parent2, Export Parent3 |
parent booklets | Parent1, Parent2, Parent3 | Parent1.csv, Parent2.csv, Parent3.csv |
Export Child | twin telephone interviews | Child | Child.csv |
Export Teacher | teacher questionnaires | Teacher | Teacher.csv |
Export 7yr admin | 7 year admin data | yr7Progress | 7yrAdmin.csv |
A convenient way of exporting these data files is to run a macro that has been saved for this purpose in the Access database. See the data files summary page and the 7 Year data files page for further information about the storage of these files.
Processing by scripts
Having exported the raw data as above, a new version of the dataset is made by running the scripts described below. The scripts must be run strictly in sequence. To run each script, simply open it in SPSS, select all the text, and click on the Run icon.
Script 1: Merging raw data sources
The main purposes of this script (filename G1_merge.sps) are to import the raw data files into SPSS; to carry out basic item variable formatting such as naming, setting variable levels and recoding; and to merge the various data files together, so as to create a basic dataset with one row of data per twin. This script also double-enters the twin-specific items from the parent booklet. The script carries out these tasks in order:
- There are 4 files of family-based raw data: the 3 files of parent
booklet data, and the file of 7 year admin data such as return dates. These raw data files all start in csv format. For each of these
4 files in turn, carry out the following actions:
- Import into SPSS
- Sort in ascending order of family identifier FamilyID
- Recode default values of -99 (missing) and -77 (not applicable) to SPSS "system missing" values
- For each variable, change the name, set the displayed width and number of decimal places, and set the SPSS variable level (nominal/ordinal/scale)
- Carry out basic recoding of categorical variables where necessary
- Drop raw data variables that are not to be retained in the datasets.
- Save as an SPSS data file.
- In the 3 parent booklet data files, in addition to the steps mentioned
above, transform and derive further variables as follows:
- Add reversed versions of behaviour items, where needed.
- Convert raw twin-pair neither/elder/younger/both items to twin-specific yes/no items
- In some cases (in the twin health section of the booklet), the conversion of twin-pair items to twin-specific items also involves combining the coding with the follow-up item, hence reducing the number of item variables. For example, the raw items about hearing problems (twin-pair neither/elder/younger/both item, followed by items asking about categories of hearing problems for each twin) are combined into a single pair of twin-specific items (incorporating both yes/no coding and the category coding if yes).
- Derive standardised twin-specific items from the raw elder twin responses and younger twin differences (parental feelings and discipline)
- Merge the 4 files of family-based data together using FamilyID as the key variable.
- Double enter the family-based data as follows:
- Compute twin identifier gtempid2 for the elder twin by appending 1 to the FamilyID. Save as the elder twin part of the family data.
- Re-compute gtempid2 for the younger twin by appending 2 to the FamilyID. Reverse the values of the Random variable. Swap over elder and younger twin values in any twin-specific variables in the family data (do this by renaming variables). Save as the younger twin part of the family data.
- Combine the elder and younger twin parts together by adding cases. Sort in ascending order of gtempid2 and save as the double entered family data file.
- There are 3 files of twin-based raw data: the file of child phone
interview test data, the file of teacher questionnaire data, plus the admin
data file containing twin IDs and birth orders. These raw data files all
start in csv format. For each of these files in turn, carry out the
following actions:
- Import into SPSS
- Sort in ascending order of twin identifier TwinID
- Recode default values of -99 (missing) and -77 (not applicable) to SPSS "system missing" values
- For each variable, change the name, set the displayed width and number of decimal places, and set the SPSS variable level (nominal/ordinal/scale)
- Carry out basic recoding of categorical variables where necessary (and add reversed versions of behaviour variables where needed)
- In the file of twin birth orders and sexes, compute the alternative twin identifier gtempid2 as the FamilyID followed by the twin order (1 or 2).
- Drop raw data variables that are not to be retained in the datasets.
- Save as an SPSS data file.
- Merge the 3 twin data files together using TwinID as the key variable.
- Double enter the twin and teacher data flags, as follows:
- Sort in ascending order of gtempid2 and save as the twin 1 part. (Note that by this stage the twin variables already have names ending in 1.)
- Change the flag variable names by changing the ending from 1 to 2. Change the values of gtempid2 to match the co-twin (change the final digit from 1 to 2 or vice versa). Re-sort in ascending order of gtempid2 and save with just the double entered variables as the twin 2 part.
- Merge the twin 1 and twin 2 parts using gtempid2 as the key variable. The double entered data flags can now be used to select twin pairs having data.
- Merge this twin data file with the double entered parent data file, using gtempid2 as the key variable. This dataset now contains all the raw data.
- Use the parent data flag, and the double entered twin and teacher data flags, to filter the dataset and delete any cases without any 7 Year data. Add the overall 7 Year data flag variable gsevenyr.
- Anonymise the family and twin IDs; the algorithm for scrambling IDs is described on another page.
- Sort in ascending order of scrambled twin ID id_twin.
- Save and drop the raw ID variables.
- Merge in essential background variables, from a separate reference dataset, using id_twin as the key variable. These include twin birth dates (for deriving ages), 1st Contact reference variables, twin sexes and zygosities, autism, medical exclusions and overall exclusion variables, all of which are already double entered where appropriate.
- Use variable gsevenyr to filter the dataset and delete cases added from the reference dataset that do not have 7 Year data.
- Save a working SPSS data file ready for the next script (filename g1merge in the \working files\ subdirectory).
Script 2: Deriving new variables
The purpose of this script (filename G2_derive.sps) is to derive scale and composite variables and twin ages from the item data. See derived 7 Year variables for full details of derivation of individual variables. The script carries out these tasks in order:
- Open the data file saved at the end of the previous script.
- Derive best estimates of the dates when the parent, twin and teacher data were completed or returned, using the full range of available dates in the raw data. Use these dates to derive the ages of the twins when the parent, twin and teacher data were completed.
- Derive a total score variable for each of the twin telephone tests. Where appropriate, "don't know" and "timed out" responses are first (temporarily) recoded so that they make zero contribution to the total score.
- Derive a flag variable to flag valid or invalid TOWRE test results.
- Create age-standardised versions of the two TOWRE test scores (word and
non-word), using the following steps:
- Import the raw data files (from csv into SPSS), containing lookup tables for corrected TOWRE scores based on age. There are two such tables: one for the 'word' test, and one for the 'non-word' test. Sort each of these files by the key variable, which is a number derived from the relevant test score and the age. Save the two files.
- Re-open the working version of the 7 Year dataset. Derive a new variable for the twin age, appropriately grouped to match the values in the TOWRE lookup tables. From this, and from the TOWRE 'word' and 'non-word' scores, derive key variables to match those used in the TOWRE lookup tables.
- Merge with each of the two TOWRE lookup table data files, in each case using the relevant key variable derived from the TOWRE score and the age. This has now added the age-standardized TOWRE scores to the dataset. Re-sort back into id_twin order.
- Derive temporary variables to identify the biological mother and father of the twins from the respondent and respondent's partner in the parent booklet. Use these to derive new variables for educational qualifications and employment categories for the twins' mother and father.
- Derive standardized TOWRE, cognitive, academic achievement and SES
composites as follows:
- Apply a filter (exclude1=0 & exclude2=0) to remove exclusions
- Standarise the necessary component items and scores
- Compute the mean of the appropriate standardised items/scores
- Standardise the mean, to make the final version of each composite
- Remove the filter
- Compute various scales from the behaviour items, from both the parent booklet and the teacher questionnaire. The behaviour scales include SDQ, PSD and ASD scales.
- Derive standardised parental feelings and discipline composites, using means of the standardised twin-specific versions of the items that were derived in the previous script.
- Drop any temporary variables that have been used to derive the new variables. Date variables are dropped at this point, having been used to derive ages.
- Save a working SPSS data file ready for the next script (filename G2derive), dropping all temporary variables that had been used during derivation of scales.
Script 3: Label variables
The purpose of this script (filename G3_label.sps) is simply to label all the variables added to the dataset so far, and to add value labels for categorical variables. The script carries out these tasks in order:
- Open the data file saved at the end of the previous script.
- Label all the variables.
- Add value labels for every integer-valued categorical variable (whether nominal or ordinal) having 3 or more different categories.
- Save a working SPSS data file ready for the next script (filename G3label).
Script 4: Double enter the twin data
The purpose of this script (filename G4_double.sps) is to double-enter all the twin-specific data in the dataset. Note that twin-specific item variables from the parent booklet are already correctly double-entered at this stage (this was achieved in script 1). The variables to be double entered in the current script are all items and scales from the twin interviews and teacher questionnaires. The script carries out these tasks in order:
- Open the data file saved at the end of the previous script.
- Create the twin 2 part (for the co-twin) as follows:
- Rename the variables (from the twin interviews and teacher questionnaire) by changing the suffix from 1 to 2.
- Modify the id_twin values so they will match the co-twin (change the final digit from 1 to 2 or vice versa).
- Re-sort in ascending order of id_twin and save as the twin 2 part, keeping only the renamed variables.
- Re-open the data file saved at the end of the previous script: this already serves as the twin 1 part of the dataset.
- Merge in the twin 2 part, using id_twin as the key variable. The dataset is now double entered.
- Place the dataset variables into a logical and systematic order (do this using a KEEP statement when saving the dataset).
- Save an SPSS data file (filename G4double in the \working files\ subdirectory).
- Save another copy as the main 7 Year dataset, with filename gdb9456.