2013-10-10 83 views
2

因此,我一直在使用SPSS的時間不長,我需要幫助創建一個變量使用兩個其他人。使用2個其他變量在SPSS中創建一個變量?

我有一個調查,併爲每個人的「家庭號碼」變量和「與戶主的關係」(頭= 1,配偶= 2,孩子= 3等)的另一個變量。 我想通過使用與每個家庭中戶主的關係來創建「家庭類型」的變量。

所以,像這樣:

If in the household there's only the head, then is 1 
If there's the head, spouse and/or children, then is 2 
If it's head plus any other type of relative, it's 3. 

如:

家用Nº - 關係

1 - 1

1 - 2

1 - 3

在家庭「1」有一個頭部(1),一個配偶(2)和一子(3),因此這將是一個「型家族的」 2.

我不不知道用什麼命令來做這件事是SPPS。誰能幫我?

回答

1

我懷疑這將需要使用AGGREGATE爲所有家庭成員分配需要的特徵,然後使用if語句來創建家庭類型。因此,讓我們從一些類似於您的示例數據開始。這使得一組長的格式的家庭。

data list free/house relation. 
begin data 
1 1 
1 2 
1 3 
2 1 
3 1 
3 2 
4 1 
4 3 
5 1 
5 2 
5 3 
5 3 
5 3 
end data. 
VALUE LABELS relation 
1 'Head' 
2 'Spouse' 
3 'Child'. 

從這裏我會建議四種類型的家庭; Single-No ChildrenCouple-No Children,Single-With ChildrenCouple-With Children。爲了獲得這些信息,我製作了一個虛擬變量,以表明一個案例是一個孩子還是一個配偶,然後彙總家庭中的最小值,爲家庭是否有任何配偶或任何孩子提供一面旗幟。

*Make flag for if have a spouse and if have a child. 
COMPUTE child = (relation EQ 3). 
COMPUTE spouse = (relation EQ 2). 
*Aggregate to get a flag for child or spouse. 
AGGREGATE 
    /OUTFILE=* MODE=ADDVARIABLES 
    /BREAK=house 
    /AnyChild = MAX(child) 
    /AnySpouse = MAX(spouse) 
    /NumChild=SUM(child) 
    /TotalFamSize=N. 

我也顯示,如何能夠得到使用SUM和孩子在aggregate命令使用N家庭總規模的總數。從這裏您可以使用一系列if語句對不同類型的家庭進行分類。

*From here can make several fam categories using DO IF. 
DO IF TotalFamSize = 1. 
    COMPUTE FamType = 1. 
ELSE IF AnySpouse = 1 AND AnyChild = 0. 
    COMPUTE FamType = 2. 
ELSE IF AnySpouse = 0 and AnyChild = 1. 
    COMPUTE FamType = 3. 
ELSE IF AnySpouse = 1 and AnyChild = 1. 
    COMPUTE FamType = 4. 
END IF. 
VALUE LABELS FamType 
1 'Single - No Children' 
2 'Couple - No Children' 
3 'Single - Children' 
4 'Couple - Children'. 
EXECUTE. 

這種使用聚合來獲得整個家庭的統計數據的邏輯應該適用於你想要生成的任何類型的統計數據。

相關問題