Advanced tables and statistics > Dealing with hierarchical data > Analysis levels > Statistics with analysis levels
 
Statistics with analysis levels
Statistics can be unreliable when you use celllev or uplev to create a table at a higher level than its axes. For example, suppose you want to know the average amount spent by credit card per respondent. The transaction details are held at the lower, credit card, level but you want the average at the higher, respondent, level. If you put an n12 element in the credit card level axis and use celllev to create the table at the respondent level, the n12 will not give what you want. Instead you must accumulate the values for the respondent in the edit section and run the table at the respondent level.
For example:
struct;read=2;ser=c(1,4);crd=c(5,6)
+lev=resp,1
+lev=ccard<resp,2
real card_tot 1
real card_a 1
real card_b 1
ed resp
/* initialize at respondent (top) level
clear card_tot, card_a, card_b
level ccard
/* accumulate total value of transactions for each respondent
card_tot = card_tot + cx(212,217)
if ( c211'1' ) card_a = card_a + cx(212,217)
if ( c211'2' ) card_b = card_b + cx(212,217)
return
end
a;op=12
tab card_ave total;anlev=ccard
tab resp_ave total;anlev=resp
l card_ave;anlev=ccard
ttlAverage Transaction Size Per Credit Card
/* increment n25 by value of each transaction
/* base is number of transactions
n25;inc=cx(212,217)
n12Total;dec=2
n25;inc=cx(212,217);c=c211'1'
n12Card A;dec=2
n25;inc=cx(212,217);c=c211'2'
n12Card B;dec=2
l resp_ave;anlev=resp
ttlAverage Amount Spent Per Respondent
/* increment n25 by value of total amount spent
/* base is number of respondents
n25;inc=card_tot
n12Total;dec=2
n25;inc=card_a
n12Card A;dec=2
n25;inc=card_b
n12Card B;dec=2
l total;anlev=resp
n10Base
Suppose you have two respondents with credit card transactions as follows:
Respondent 1,
Card A
 
1.0
 
Card A
 
2.0
 
Card B
 
3.0
Respondent 2,
Card A
 
4.0
 
Card B
 
5.0
The tables produced would be:
Average Transaction Size Per Credit Card

Base
Total 3.00
Card A 2.33
Card B 4.00
Average Amount Spent Per Respondent

Base
Total 7.50
Card A 3.50
Card B 4.00
See also
Analysis levels