17
ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

Embed Size (px)

Citation preview

Page 1: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

How to Write A Tax Benefit Model

Asghar AdelzadehGraham Stark

Page 2: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Coding Style

Use meaningful names; Organize code into procs; Use constants instead of magic numbers Group related data together using

structs; Read one good programming book

Page 3: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Coding Style: Use Meaningful Names

Try to avoid:

if( x[202,1] <= yy[203,9] );

what is x? What's special about element [202,1]?

Better:

if( income > tax_allowance);

Page 4: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Coding Style: Use Constants

Try to avoid:

if( sex == 2 );

what does the 2 mean (the second sex?)

Better (though longer):

declare Male = 2;...if( sex == Male );

Page 5: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Coding Style: Use Structs to Model complex Data

struct Adult{ scalar age; scalar sex; scalar economic_position; matrix incomes;};

longer to write, but worth it in long run

Page 6: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Coding Style: Use Procs to break up code into chunks

proc calculate_tax( struct Adult ad, struct Income_Tax inc_tax );

local tax; local income; income = ad.incomes[ EARNINGS ] -

inc_tax.allow; tax = 0.0; if( income > 0 ); tax = income * inc_tax.rate; endif; retp( tax );endp;Don't use this routine!

Page 7: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Gathering Information

Before you start coding: Gather tax returns, tax law, claim forms; Work out examples of each calculation on

paper; Check characteristics of your dataset

against aggregate statistics. Check the exact questions in the survey

Page 8: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Structure Of The Example Tax Benefit Model

Household.prg – model a household; routines to load households from a file, uprate them and so onRunSettings.prg – general settings for a run, for example, inflation rates , switches to turn on special procedures such as labour supply routines, and the like.Parameters.prg - Tax System Parameters, for example tax rates and allowances, money amounts for pensions and the like, and associated routines (uprating, for example);Results.prg – The results for one full calculation for one household (taxes due, net incomes, pensions payable, net incomes, poverty states and so forth); routines to compare two sets of results;Calculator.prg – once we've got all the above in place, we can actually do some sums. This file contains routines to calculate one Results record for one Household, using one set of Parameters and RunSettings. The file supplied to you is very basic, with just two simple routines. In reality, this module might get very large, and be best split into sub-modules (income tax, indirect taxes and so on);TaxBenefitModel.prg – finally, the module to run the whole thing can be quite short: it needs to import all the other modules, initialize them and run the calculations by looping over all the households available, calling the calculator and accumulating the results.

Page 9: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Household.prg

Holds structs to represent a household Also, constants for commonly used

items (gender, regions..) Model data as nested structs (household

contains people, people contain incomes, demographics, etc)

Follow structure of original dataset, where possible

Page 10: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

RunSettings.prg

Holds information common to run Examples: inflation rates for uprating Advanced models might have lots of

information here (behavioral parameters, macroeconomic information ...)

Page 11: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Parameters.prg

Hold structs for storing tax rates, benefit levels, etc.

Examples: sys.income_tax.rate=0.26; sys.vat.rate[ FOOD ] = 0.22;

Page 12: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Results.prg

Holds results for one set of calculations on one household

Examples: tax due, poverty state (in/out of poverty)

Follow structure of Household.prg (results for individuals, then for the household as a whole..)

Page 13: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Calculator.prg

Now we've got all this, we can do some sums!

Calculator.prg does the actual tax/benefit calculations;

Produce one results record for one household and one set of parameters and one run settings struct

As such should provide a public proc like:

proc calculate_results( struct Household hh, struct Fiscal_System tb_sys,

struct Run_Settings settings );

Page 14: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Calculator.prg (continued)

Write a proc for each component of the system being modeled: income tax, vat, poverty state..

Break complex systems up into sub procs..

Page 15: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

TaxBenefitModel.prg

This drives the program Initialize household data, parameters,

output routines, run settings; Loop round households, call

calculate.prg main proc for each one, for current and reformed tax systems;

Accumulate the results If the modules have been set up as

above, this should be short (50-60 lines, perhaps)

Page 16: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Test!

Write a GAUSS test for every single proc that you write;

Keep the the test programs in a separate file (preferably in a separate directory);

Run your tests every time you modify your program.

Page 17: ADRS Applied Development Research Solutions How to Write A Tax Benefit Model Asghar Adelzadeh Graham Stark

ADRSApplied Development

Research Solutions

Does the model match reality?

Check your aggregate outputs against official figures (tax revenues, benefits paid... ).

May not always match: Data may undersample some groups (rich,

sick..) Survey may ask wrong questions (e.g.

Incomes of people not receiving a regular wage);

People may lie: I don't drink, smoke that much!;

People may avoid paying taxes, or not claim benefits