Does anybody know how I copy a variable from one dataset to another
dataset in SPSS? The copy-paste method only results in an empty
variable.
Thanks!
You can copy-paste the variable definition (datatype, length, ect) in
the variable view. After that you can paste the data in the variable
view. When doing the paste of the data, make sure you select at least
as many cells as you are going to paste. SPSS is not like Excel where
you can paste into one cell and it writes the data to the cells below
as needed. You need to select every cell into which you want to paste
data.
It seems to me that merging files (MATCH FILES) might be easier. If a
tutorial is needed, click on the Data Management link at the site
given below, then look for "Merging (MATCH merging) SPSS data files".
http://www.ats.ucla.edu/stat/spss/
--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."
Good catch Bruce, match files is definitely more user-friendly and
less error-prone. There are some things to be aware of when you're
matching files to add variables: when you merge, you need a variable
that exists in both datasets, and uniquely identifies each case in
both datasets. The merging variable must be of the same type AND
length in both datasets, and you have to make sure that both datasets
are sorted ascending on the matching variable.
Or, it is *possible* to match to files without any ID variable
in the syntax. (At least, it used to be.) (Jon - Perhaps this
behavior ought to be available *only* when invoked by a
special keyword?)
If you give it no ID variable, SPSS will assume that the lines
belong together, one by one, in the order that they exist
respectively in the two files.
- This should never be used if you can avoid it. Unsafe.
- You should be *aware* of it, to avoid omitting your ID variables.
You certainly don't want this outcome by accident.
--
Rich Ulrich
Hi Rich,
if this was possible before, maybe it still is. I did not know that
this used to be possible.
>
> Or, it is *possible* to match to files without any ID variable
> in the syntax. (At least, it used to be.) (Jon - Perhaps this
> behavior ought to be available *only* when invoked by a
> special keyword?)
>
> If you give it no ID variable, SPSS will assume that the lines
> belong together, one by one, in the order that they exist
> respectively in the two files.
> - This should never be used if you can avoid it. Unsafe.
> - You should be *aware* of it, to avoid omitting your ID variables.
> You certainly don't want this outcome by accident.
Yes, one can still match with no use of BY. But as Rich notes, it can
be dangerous. Here's an example.
* --- Start of example --- .
data list list / id x1 (2f5.0).
begin data
1 5
2 4
3 4
4 2
5 4
end data.
dataset name dataset1 .
data list list / id x2 (2f5.0).
begin data
1 3
3 5
4 3
5 5
end data.
dataset name dataset2 .
* MATCH FILES without BY .
match files
file = 'dataset1' /
file = 'dataset2' .
exe.
list.
* MATCH FILES with BY .
match files
file = 'dataset1' /
file = 'dataset2' /
BY ID .
exe.
list.
* --- End of example --- .
Notice that ID number 2 is missing from the second data set. Here is
the output.
From the first MATCH FILES (without BY):
id x1 x2
1 5 3
2 4 5 <-- Incorrect matching from here down
3 4 3
4 2 5
5 4 .
From the second MATCH FILES (with BY):
id x1 x2
1 5 3
2 4 . <-- Correct!
3 4 5
4 2 3
5 4 5
--
Bruce Weaver
bwe...@lakeheadu.ca
Yes, you can match without an explicit id variable. Obviously this is
risky except under controlled conditions so having an id variable is
certainly recommended. AFAIK, this has been possible for over 25
years.
-Jon