Snippets
Test
Indicators
Presidential indicators
# Copyright © Ferra Solutions (Pty) Ltd. All rights reserved.
# Presidential indicators
# Create an indicator for each president
# It starts out empty
zumi = empty(); # Zuma indicator
cyri = empty(); # Ramaphosa indicator
bushi = empty(); # Bush indicator
obami = empty(); # Obama indicator
trmpi = empty(); # Trump indicator
# Note the day on which each president
# entered office (e.g. zum0) and on
# which he exited office (e.g. zum1)
zum0 = dateIndex( 2009, 5, 9 );
zum1 = dateIndex( 2018, 2, 14 );
cyr0 = dateIndex( 2018, 2, 15 );
cyr1 = dateIndex( 2021, 1, 1 );
bush0 = dateIndex( 2001, 1, 20 );
bush1 = dateIndex( 2009, 1, 19 );
obam0 = dateIndex( 2009, 1, 20 );
obam1 = dateIndex( 2017, 1, 19 );
trmp0 = dateIndex( 2017, 1, 20 );
trmp1 = dateIndex( 2021, 1, 1 );
# Loop from some time in the past to
# some distant time in the future
i = dateIndex( 2000, 1, 1 );
while ( i < dateIndex( 2020, 12, 31 ),
# Set the various indicators
zumi [ i ] = and( zum0 <= i, i <= zum1 ),
cyri [ i ] = and( cyr0 <= i, i <= cyr1 ),
bushi[ i ] = and( bush0 <= i, i <= bush1 ),
obami[ i ] = and( obam0 <= i, i <= obam1 ),
trmpi[ i ] = and( trmp0 <= i, i <= trmp1 ),
# Move to next date
i = i + 1
);
# Set the aggregation for each series
setProperty( "zumi", "aggregation", "average" );
setProperty( "cyri", "aggregation", "average" );
setProperty( "bushi", "aggregation", "average" );
setProperty( "obami", "aggregation", "average" );
setProperty( "trmpi", "aggregation", "average" );
# Store the indicators back into the project
dataReplace( zumi );
dataReplace( cyri );
dataReplace( bushi );
dataReplace( obami );
dataReplace( trmpi );
Employment Test 1
Obama vs Trump
# Copyright © Ferra Solutions (Pty) Ltd. All rights reserved.
# This requires that the presidential indicators
# snippet have been executed successfully before.
# Remember to set the frequency of the
# calculation to match that of the series
# Also, calculate change in logs or similar,
# often levels will not work for this test
y = dLn( dataFred( "PAYEMS" ) );
# Load the presidential indicators
obami = dataGet( "obami", "CALC", "CALC" );
trmpi = dataGet( "trmpi", "CALC", "CALC" );
# Now we can use the indicators to
# chop the data down to size
Obama = replaceZero( obami > 0.5, . ) * y;
Trump = replaceZero( trmpi > 0.5, . ) * y;
# Delete the existing report to
# prevent clutter from buidling up
reportDelete( "Employment" );
# Now we can create the report
# The # in the string requests a report
# The = implies that we assume variances are equal
testMeans( "#=Employment", Obama, Trump );
Employment Test
Obama vs Trump
# Copyright © Ferra Solutions (Pty) Ltd. All rights reserved.
# This requires that the presidential indicators
# snippet have been executed successfully before
# AND that the PAYEMS series have been downloaded
# from FRED. The other test will download the data
# as part of the calculation.
# Calculate the percentage change in PAYEMS
# We will test on that
y = 100 * p ( PAYEMS );
# Load the presidential indicators
obami = dataGet( "obami", "CALC", "CALC" );
trmpi = dataGet( "trmpi", "CALC", "CALC" );
# Now we can use the indicators to
# chop the data down to size
Obama = replaceZero( obami > 0.5, . ) * y;
Trump = replaceZero( trmpi > 0.5, . ) * y;
# Delete the existing report to
# prevent clutter from buidling up
reportDelete( "Employment" );
# Now we can create the report
# The # in the string requests a report
# The = implies that we assume variances are equal
testMeans( "#=Employment", Obama, Trump );
Rand Test
Zuma vs Ramaphosa
# Copyright © Ferra Solutions (Pty) Ltd. All rights reserved.
# This requires that the presidential indicators
# snippet have been executed successfully before.
# This also requires that EXSFUS have been
# downloaded from FRED to work.
# Remember to set the frequency of the
# calculation to match that of the series
# Also, calculate change in logs or similar,
# often levels will not work for this test
y = 100 * p ( EXSFUS );
# Load the presidential indicators
zumi = dataGet( "zumi", "CALC", "CALC" );
cyri = dataGet( "cyri", "CALC", "CALC" );
# Now we can use the indicators to
# chop the data down to size
Zuma = replaceZero( zumi > 0.5, . ) * y;
Ramaphosa = replaceZero( cyri > 0.5, . ) * y;
# Delete the existing report to
# prevent clutter from buidling up
reportDelete( "Rand" );
# Now we can create the report
# The # in the string requests a report
# The @ requests that averages be used
# The default is to use medians
testVariances( "#@Rand", Zuma, Ramaphosa );