Custom Tables And Calculated Percentages

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom Tables And Calculated Percentages

SUBSCRIBE SPSSX-JohnF
The "Custom Tables" code below (data included) produces a table of the counts representing the denominator and numerator for each period broken out by gender, however I can't figure out how to compute a percent based on each period's denominator and numerator count representing each gender per period.  

* Encoding: UTF-8.
DATA LIST /ID 1-3 SEX 5 (A) AGE 7-8 OPINION1 TO OPINION5 10-14 denominator 15 numerator 16 period 17-20 (A) .
BEGIN DATA
001 m 28 1221210 15A
002 f 29 2121210 16A
003 f 45 3214501 16A
004 m 17 1119411 17A
005 m 29 1221211 17A
006 f 30 2121211 17A
007 f 47 3214511 15A
008 m 18 1119411 15A
009 m 28 1221210 15A
010 f 29 2121210 16A
011 f 45 3214501 16A
012 m 17 1119411 16A
013 f 29 2121210 16A
014 f 45 3214511 17A
015 f 17 1119410 17A
END DATA.
value labels denominator numerator
0'NA'
1'Applicable'.
exe.

* Custom Tables.
CTABLES
  /VLABELS VARIABLES=SEX denominator period numerator DISPLAY=LABEL
  /TABLE SEX [C] BY denominator [C] > period [C][COUNT F40.0] + numerator [C] > period [C][COUNT
    F40.0]
  /CATEGORIES VARIABLES=SEX ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER
  /CATEGORIES VARIABLES=denominator [1] EMPTY=INCLUDE
  /CATEGORIES VARIABLES=period ORDER=A KEY=VALUE EMPTY=EXCLUDE
  /CATEGORIES VARIABLES=numerator [1] EMPTY=INCLUDE
  /CRITERIA CILEVEL=95.

I other words I am trying to add the following 3 columns on the right side of table which the custom tables code above produces.  I am thinking it can't be done within custom tables.  Those percentages are based on 15A's numerator divided by 15A's denominator, etc.  Any help would be appreciated.......

    Period Percentages
 15A          16A 17A
               
100.0% 66.7% 66.7%
33.3% 100.0% 100.0%
50.0% 75.0% 80.0%

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Tables And Calculated Percentages

Jon Peck
Unfortunately, post computes cannot span variables, so you can't have a formula involving both numerator and denominator to get those percentages.

If you are willing to settle for each percentage being next to its numerator column, you can do that with STATS TABLE CALC after running CTABLES.  For example,
STATS TABLE CALC SUBTYPE="customtable" PROCESS=PRECEDING 
/TARGET FORMULA="x[0]/x[-3] * 100." DIMENSION=COLUMNS OUTLEVEL=-2  LOCATION=3 4 5
    LABEL="Pct" MODE=after HIDEINPUTS=NO
/FORMAT CELLFORMAT="##.#%" DECIMALS=1  INVALID="".

If you restructured the table like this
CTABLES
  /VLABELS VARIABLES=SEX period numerator denominator DISPLAY=DEFAULT
  /TABLE SEX [C] BY period [C] > (numerator [C][COUNT F40.0] + denominator [C][COUNT F40.0])
  /CATEGORIES VARIABLES=SEX period ORDER=A KEY=VALUE EMPTY=EXCLUDE
  /CATEGORIES VARIABLES=numerator [1] EMPTY=INCLUDE
  /CATEGORIES VARIABLES=denominator [1] EMPTY=INCLUDE
  /CRITERIA CILEVEL=95.

You could use TABLE CALC like this.
STATS TABLE CALC SUBTYPE="customtable" PROCESS=PRECEDING 
/TARGET FORMULA="x[-1]/x[0] * 100." DIMENSION=COLUMNS OUTLEVEL=-2  LOCATION="denominator" LEVEL=-3 REPEATLOC=YES
    LABEL="Pct" MODE=after HIDEINPUTS=NO
/FORMAT CELLFORMAT="##.#%" DECIMALS=1  INVALID="".

STATS TABLE CALC can be installed from the Extensions menu if you don't already have it.


On Mon, Dec 10, 2018 at 12:42 PM SUBSCRIBE SPSSX-JohnF <[hidden email]> wrote:
The "Custom Tables" code below (data included) produces a table of the counts representing the denominator and numerator for each period broken out by gender, however I can't figure out how to compute a percent based on each period's denominator and numerator count representing each gender per period. 

* Encoding: UTF-8.
DATA LIST /ID 1-3 SEX 5 (A) AGE 7-8 OPINION1 TO OPINION5 10-14 denominator 15 numerator 16 period 17-20 (A) .
BEGIN DATA
001 m 28 1221210 15A
002 f 29 2121210 16A
003 f 45 3214501 16A
004 m 17 1119411 17A
005 m 29 1221211 17A
006 f 30 2121211 17A
007 f 47 3214511 15A
008 m 18 1119411 15A
009 m 28 1221210 15A
010 f 29 2121210 16A
011 f 45 3214501 16A
012 m 17 1119411 16A
013 f 29 2121210 16A
014 f 45 3214511 17A
015 f 17 1119410 17A
END DATA.
value labels denominator numerator
0'NA'
1'Applicable'.
exe.

* Custom Tables.
CTABLES
  /VLABELS VARIABLES=SEX denominator period numerator DISPLAY=LABEL
  /TABLE SEX [C] BY denominator [C] > period [C][COUNT F40.0] + numerator [C] > period [C][COUNT
    F40.0]
  /CATEGORIES VARIABLES=SEX ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER
  /CATEGORIES VARIABLES=denominator [1] EMPTY=INCLUDE
  /CATEGORIES VARIABLES=period ORDER=A KEY=VALUE EMPTY=EXCLUDE
  /CATEGORIES VARIABLES=numerator [1] EMPTY=INCLUDE
  /CRITERIA CILEVEL=95.

I other words I am trying to add the following 3 columns on the right side of table which the custom tables code above produces.  I am thinking it can't be done within custom tables.  Those percentages are based on 15A's numerator divided by 15A's denominator, etc.  Any help would be appreciated.......

    Period Percentages         
 15A              16A    17A

100.0%  66.7%   66.7%
33.3%   100.0%  100.0%
50.0%   75.0%   80.0%

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Tables And Calculated Percentages

Jon Peck
But if you restructure the denominator and numerator into categories, you could use Postcompute

On Mon, Dec 10, 2018 at 2:14 PM Jon Peck <[hidden email]> wrote:
Unfortunately, post computes cannot span variables, so you can't have a formula involving both numerator and denominator to get those percentages.

If you are willing to settle for each percentage being next to its numerator column, you can do that with STATS TABLE CALC after running CTABLES.  For example,
STATS TABLE CALC SUBTYPE="customtable" PROCESS=PRECEDING 
/TARGET FORMULA="x[0]/x[-3] * 100." DIMENSION=COLUMNS OUTLEVEL=-2  LOCATION=3 4 5
    LABEL="Pct" MODE=after HIDEINPUTS=NO
/FORMAT CELLFORMAT="##.#%" DECIMALS=1  INVALID="".

If you restructured the table like this
CTABLES
  /VLABELS VARIABLES=SEX period numerator denominator DISPLAY=DEFAULT
  /TABLE SEX [C] BY period [C] > (numerator [C][COUNT F40.0] + denominator [C][COUNT F40.0])
  /CATEGORIES VARIABLES=SEX period ORDER=A KEY=VALUE EMPTY=EXCLUDE
  /CATEGORIES VARIABLES=numerator [1] EMPTY=INCLUDE
  /CATEGORIES VARIABLES=denominator [1] EMPTY=INCLUDE
  /CRITERIA CILEVEL=95.

You could use TABLE CALC like this.
STATS TABLE CALC SUBTYPE="customtable" PROCESS=PRECEDING 
/TARGET FORMULA="x[-1]/x[0] * 100." DIMENSION=COLUMNS OUTLEVEL=-2  LOCATION="denominator" LEVEL=-3 REPEATLOC=YES
    LABEL="Pct" MODE=after HIDEINPUTS=NO
/FORMAT CELLFORMAT="##.#%" DECIMALS=1  INVALID="".

STATS TABLE CALC can be installed from the Extensions menu if you don't already have it.


On Mon, Dec 10, 2018 at 12:42 PM SUBSCRIBE SPSSX-JohnF <[hidden email]> wrote:
The "Custom Tables" code below (data included) produces a table of the counts representing the denominator and numerator for each period broken out by gender, however I can't figure out how to compute a percent based on each period's denominator and numerator count representing each gender per period. 

* Encoding: UTF-8.
DATA LIST /ID 1-3 SEX 5 (A) AGE 7-8 OPINION1 TO OPINION5 10-14 denominator 15 numerator 16 period 17-20 (A) .
BEGIN DATA
001 m 28 1221210 15A
002 f 29 2121210 16A
003 f 45 3214501 16A
004 m 17 1119411 17A
005 m 29 1221211 17A
006 f 30 2121211 17A
007 f 47 3214511 15A
008 m 18 1119411 15A
009 m 28 1221210 15A
010 f 29 2121210 16A
011 f 45 3214501 16A
012 m 17 1119411 16A
013 f 29 2121210 16A
014 f 45 3214511 17A
015 f 17 1119410 17A
END DATA.
value labels denominator numerator
0'NA'
1'Applicable'.
exe.

* Custom Tables.
CTABLES
  /VLABELS VARIABLES=SEX denominator period numerator DISPLAY=LABEL
  /TABLE SEX [C] BY denominator [C] > period [C][COUNT F40.0] + numerator [C] > period [C][COUNT
    F40.0]
  /CATEGORIES VARIABLES=SEX ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER
  /CATEGORIES VARIABLES=denominator [1] EMPTY=INCLUDE
  /CATEGORIES VARIABLES=period ORDER=A KEY=VALUE EMPTY=EXCLUDE
  /CATEGORIES VARIABLES=numerator [1] EMPTY=INCLUDE
  /CRITERIA CILEVEL=95.

I other words I am trying to add the following 3 columns on the right side of table which the custom tables code above produces.  I am thinking it can't be done within custom tables.  Those percentages are based on 15A's numerator divided by 15A's denominator, etc.  Any help would be appreciated.......

    Period Percentages         
 15A              16A    17A

100.0%  66.7%   66.7%
33.3%   100.0%  100.0%
50.0%   75.0%   80.0%

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


--
Jon K Peck
[hidden email]

--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Tables And Calculated Percentages

SUBSCRIBE SPSSX-JohnF
In reply to this post by SUBSCRIBE SPSSX-JohnF
Thanks....I was able to load the ext., however I keep getting the following error....

STATS TABLE CALC Subcommand TARGET: OUTLEVEL is not a valid keyword.

Any thoughts?  Thanks Again....

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Tables And Calculated Percentages

SUBSCRIBE SPSSX-JohnF
In reply to this post by SUBSCRIBE SPSSX-JohnF
Problem resolved....evidently the "Outlevel" wasn't necessary at least for the first suggested approach.  Thanks.....

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD