Wednesday, October 24, 2012

Now that was an embarassment, loops are very inefficient

R's learning curve can be very steep, and thankfully I am surrounded by intelligent and smart colleagues. The point is that the loop script in the last post is embarrassingly inefficient, and will work horribly if one intends to simulate a large sample.

Here's a much more elegant solution, for 3.1 of EMT,but this time using the function argument in R.The script is provided by Evan Jo.


ARsample<-function(beta1=1,beta2=.8,n=25,y0=0){
y<-vector(length=n+1);y[1]<-y0
for (i in 2:n+1){
y[i]<-beta1+beta2*y[i-1]+rnorm(1)}

m<-embed(y,2);return(data.frame(y=m[,1],y1=m[,2]))};

meanbeta<-function(samplesize=25,n=100){
m<-data.frame(beta1=NA,beta2=NA);
for(i in 1:n){m[i,]<-coef(lm(y~y1,data=ARsample(n=samplesize)))}
return(colMeans(m));}

In particular look at how efficient this script is compared to the previous one.

And finally, this is why the honours stream is so much more intellectually rewarding to be in.

PS: Don't worry, I will still be writing about economics, and hopefully when Quantdary takes off we'll start having more interesting economics/finance related posts.

Saturday, October 20, 2012

Simulation Script for ETM Question 3.1(Public Service)

I promised I'll update my blog, but I have been really really busy. Anyway, this post is not about the KLCI as promised(sorry to disappoint,I hardly had time for myself either), but rather, it is a loop for Q3.1 in Davidson and McKinnon's Econometric Theory and Methods. For all the poor souls who have just started learning R.




B1<-1
B2<-0.8
y0<-0
B1hat<-numeric(0)
B2hat<-numeric(0)

for(j in 1:100){
residualsj<-numeric(0)
residualsj<-rnorm(200,0,1)
ysimj<-y0
for(i in 1:200){
ynew<-B1+B2*ysimj[i]+residualsj[i]
ysimj<-c(ysimj,ynew)
}
OLSj<-lm(ysimj[2:201]~ysimj[1:200])
beta1j<-coefficients(OLSj)[1]
beta2j<-coefficients(OLSj)[2]
B1hat[j]<-beta1j
B2hat[j]<-beta2j
}


Time permitting I'll write an explanatory note with the #, although I hardly doubt it with midterms and a lot of other deadlines vying for whatever precious time I have. To change the sample size just change the numbers in the "i" part of the loop. To change the number of runs, just change the numbers in the j part of the loop.

Update:I made some errors in the previous post and those have since be corrected. Note that this script is meant to simulate an OLS drawing from 200 observations 100 times, and feel free to tweak around to adjust the trials and sample size.

This should also make it easier for you to attempt the last 2 questions. For information on how to extract vectors out from a data frame and then transforming it, I'd refer you to Mirza Trokic's website.
http://www.mirzatrokic.ca/aes.html

He has the most concise and helpful R guide that I have ever seen.


Sunday, April 15, 2012

Orszag on the secondary effects of Food Stamp programmes

Readers of this blog may be familiar with my affinity for food stamp programmes. Not only have I argued in a previous post that this is the holy grail of automatic stabalisers, but I also feel it is a social safety net with incontrovertible utility.

Peter Orszag (former chairman of the Office of Management and Budget for President Obama) recently wrote an opinion piece for Bloomberg about the secondary effects of Food Stamp programmes on students.

As a student of econometrics and behavioural economics I am inspired by the work that has been done to quantify the impacts of such programmes.

P/S: Due to the rigour of the my academic programme I have not updated my blog as frequently as I had hoped. As a sneak peek, the next post has to do with the KLCI Index, so Malaysian readers interested in equities might find it interesting.

Tuesday, October 4, 2011

SNED Stock Market Challenge:Beat the Market

So a little brain child of my fellow executives and I will be on full swing at McGill soon.

Here's the link.

Basically this works like a fantasy soccer/hockey/football game, the top 3 player with the highest portfolio value at the end of the period will walk away with the money from the pool.

50% of the registeration fee will be diverted to support TamTams Africa and finance SNED's microfinance portfolio while the other 50% will be directed to the prize pool.

Saturday, July 30, 2011

"Stamping" inflation out of national woes

The Star reports that the government is considering a food stamp programme to help alleviate the burdens of Malaysians in accommodating inflation. In a nice coincidence I was drafting this post a few days back, so in principle this is a programme that I endorse strongly.

The gradual phasing-out of subsidy programmes announced by the government has become a national woe, leading many to view the adjustment of commodities in the domestic market to world prices a painful pill to swallow in the short term. In all fairness the long term benefits that accrue from subsidy removal programmes
are huge. However that doesn't mean that we should act as strict utilitarianism and ask those who are harmed the most by this transition to sacrifice for the greater good. As income is not catching up with the removal of subsidies and the general rise of the price level, most Malaysians are feeling the pinch as their purchasing power declines.

As an aside,there is a link between net disposable income (wages,capital gains etc minus taxes and added with subsidy/allowance/benefits), the price level and purchasing power. It follows logically from
purchasing power = net domestic income/price level that we get:
Change in purchasing power = change in net disposable income/change in price level

Why is a food stamp programme a good idea?
Perhaps if one were to ask Bill Clinton this question he might answer it all depends on what you mean by "good."So let it be noted that the main criteria behind my support for the programme are 1) the efficacy of the food stamps to sustain the purchasing power of affected groups as Malaysia adjusts to the world price for hitherto subsidised commodities, 2) the potential role of the programme as a stabaliser, and 3)the empirical backing for the multiplier effect of the programme.

  1. Efficacy of food stamps to sustain purchasing power
    The efficacy of food stamps to sustain purchasing power should not be evaluated chiefly by how much it maintains purchasing power by increasing net disposable income to offset inflation. Purchasing power ought to be sustained and/or increased with a combination of nominal wage adjustments,tax effects, inflation management in addition to entitlement programmes like food stamp programmes and unemployment insurance. Furthermore the case for the efficacy of food stamps is consolidated in the sense that it achieves the objective of protecting the purchasing powers of citizens without introducing the price distortions, resource misallocation and deadweight loss to the economy introduced by subsidy programmes. In a related vein, my objection to the blanket-subsidy programme in place is that it applies to people for all levels of income. By subsidising say, the fuel of gas-guzzling cars we are essentially imposing an implicit penalty on people who do not own expensive gas-guzzlers. In essence this is a regressive penalty for the lower income group, it would be the same as asking residents in low-cost apartments to pay a 25% property tax so that we can levy a 15% property tax for those living in penthouses or condominiums. In addition, subsiding the high-income group is akin to saying at higher levels of income, an additional 1 dollar has the same utility as an additional 1 dollar at lower levels of income. This is a fallacy for a welfare state that justifies its social welfare programmes out of Benthamite philosophy! (See Reinhardt for instance).  So in summary the food stamp programme is a good idea for it achieves the desired social goal without the problems introduced by subsidy programmes. 
  2. The potential role of the programme as a stabaliserThe Economist newspaper recently published an article about the food stamp programme in the United States of America. The article observes that "spending on food stamps has risen so quickly because, unusually, almost all the needy are automatically and and indefinitely eligible for them." This makes the progamme a good stabaliser since spending on the programme will automatically increase during a recession and decrease during a boom.So in instituting this programme we not only have a mechanism that maintains the purchasing power of citizens in an equitable manner, it also helps moderate the swings in recessions and booms. Of course architects of the programme must be careful to delineate the cut-off point and above all be sensitive to the marginal tax that may be affected, or else in its efforts to break out of the "middle-income nation trap" it might inadvertently introduce an income trap with its policies. This conjecture will be discussed in the policy challenges part of the post. 
  3. The empirical backing for the multiplier effect of the programme
    From the same Economist article above, 
"When Moody’s Analytics assessed different forms of stimulus, it found that food stamps were the most effective, increasing economic activity by $1.73 for every dollar spent. Unemployment insurance came in second, at $1.62, whereas most tax cuts yielded a dollar or less."

So in addition to all of the advantages discussed above it appears that food stamps generate more   income per dollar spent. Automatic fiscal stabalisers that have a high (relatively speaking) multiplier effect is the holy grail of all fiscal policies. Rarely are there any effective mechanisms that can stimulate the economy automatically without having economic rationality hijacked by populist but harmful politicking.

Policy Challenges
Perhaps the greatest policy challenge is to delineate the cut-off points. Civil servants drafting out the proposal must first decide whether the value of food stamps issued is a linear function of income (that is decreasing value of food stamps issued as income increases), or would it be a much more "piece-wise" approach i.e. (food stamps valued at MYR X for the income range a to b; food stamps valued at MYR Y for the income range c to d etc etc). In addition it is worth reiterating that I said  "Purchasing power ought to be sustained and/or increased with a combination of nominal wage adjustments,tax effects, inflation management in addition to entitlement programmes like food stamp programmes and unemployment insurance." I have warned of the dangers of inadvertently institutionalising an income trap in our efforts to break out of the middle-income nation trap. This blog post from Prof Greg Mankiw sums up my fear.

My suggestion to the DPM is to draw in officials from the revenue agency, central bank, treasury,social welfare department and the economic planning board to draft out the proposal together. The success of the programme, and that of eliminating the danger of an institutionalised income trap requires a broad view, not just implementing a food stamp programme in isolation.

Update:The minister for Women,Family and Community Development says that the programme is targeted mainly at the poor. The federal poverty(absolute) level in the Peninsula is RM430/month. So the effects discussed above would be small(since absolute poverty according to official figures have gone down) but still significant. Yes,I know someone fudged the data for poverty by redefining the baseline, but that is something for another blog post. This also means that policies targeting sustainable purchasing power will have to come from nominal wage adjustment(which is why the minimum wage law was legislated), marginal tax adjustments in the future and of course, whether the Central Bank will validate inflation (it elected not to raise interest rate in the last round). 

Thursday, July 28, 2011

"It makes economic sense, if you think economically."

One day in the midst of an economics class amongst a sea of hungover and facebook-occupied freshmen I began to ponder the implications of the Economics professor's statement.

"It makes economic sense, if you think economically." 


There's an air of dissonance to the statement, unsettling even for it projects a sense of nihilism. If a single problem can make various forms of sense, "common sense, social sense, moral sense" what have you, that would have meant a single objective problem would have equally valid explanations drawn from established theories from varying disciplines. Of course in most cases this is fine, the world is sufficiently complex that a lot of factors are at work simultaneously.

But what if all of these trustworthy tools of academia- fortified by statistically significant empirical evidence - offer significantly different predictions? That would mean a moment of crisis for all of social science, as hard sciences like physics (quantum mechanics vs theory of relativity) could empathise.

That led me to think about the notion of the economic man, the rational decision maker populating economic models that came to life from Morgenstern and von Neumanns' pages. Economists are prone to be exasperated when they are accused of being out of touch with reality to populate their models with such agents. Yet one can easily see how economists come to such expectations of the ordinary Joes, it just follows logically if one's goal is to optimise scarce resources, even when some of the payoffs are random and/or only probabilistic. Yet psychologists(Kahnemann and Tversky for instance) have aptly demonstrated that empirical evidence weights unfavourly against the economists' expectation, and when one looks at the data set they presented one could only think that it then,to modify my professor's quote " to make psychological sense, if you think psychologically."

So what do we make of all these? In spite of how much economists (especially those writing textbooks) pride themselves to ground their thoughts more on positive rather than normative analysis, the expected utility theorem is in effect a logically superior normative analysis.On the other hand, Cognitive Psychology and some sub-fields of Sociology may offer better positive descriptions of  the behaviour of agents. For a science that aims to study how to optimise scare resources, all scientific endavours within Economics is fueled by the motivation to make the most all of scare resource. Economists are widely documented to be the ones with "economically correct" answers (see Thaler for instance).

Ultimately my opinion is that research in Economics should continue in two distinct but ultimately convergent paths. The first concerns the question "how do we optimise?" which is built up on the surfeit of theorems that have blessed our understanding of how the economy works; the second concerns "how do agents actually behave?" which could be built up and drawn from psychology,sociology and behavioural economics. Perhaps the best anecdote is provided by Richard Thaler, who in modifying Friedman's billiard player analogy offered that perhaps the expert billiard playing making strategic moves with his understanding of physics and mathematics is to economists as the average players who plans at most 2-3 strategic moves ahead as that of the average decision maker.

Only when we are certain of how the actual behaviour of agents diverge from rational behaviour that we can offer policy prescriptions that are guided by reason, supported by empirical evidenced and refined by moral intuitions.

Suggested Reading
  1. "Choices, Values and Frames." Daniel Kahnemann and Amos Tversky. Published in American Psychologist, 39:4,341-50
  2. "Prospect Theory, An Analysis of Decision under Risk". Daniel Kahnemann and Amos Tversky. Published in Econometrica, 47:2,263-91, 1979.
  3. "Mental Accounting Matters." Richard Thaler.
  4. "Toward a Positive Theory of Consumer Choice." Richard Thaler. 

Sunday, July 3, 2011

Inflation:Now you see it,now you don't?

Priscilla Lim,a PhD candidate at the University of Nothingham Malaysia campus recently wrote an op-ed to The Star questioning whether empirical evidence catches up with anecdotal ones on the erosion of purchasing power due to inflation.From what I could gather she argues that for the moment there doesn't appear to be adverse effects from inflation since "residents in Kuala Lumpur have similiar purchasing power with their counterparts in Singapore.Their purchasing power also tops that of Shanghai,Beijing and nearby Bangkok and Jakarta." Her reasoning is that since all these comparison countries do not implement subsidies but "wages have risen in tandem with the rapidly rising costs of living in those countries" there shouldn't be an erosion in purchasing power. However she noted that due to the subsidies and "stickiness" (in my own words) of domestic prices to adjust to changes in world prices, along with wage adjustment lags would eventually lead to upward pressure on wages. The implication is of impending cost-push inflation (which may or may not lower purchasing power,depending on how nominal wages adjust).

My thought is that inflation(with a lag in wage adjustment) is not only imminent but it is already upon us after the round of subsidy rationalisation as measured by upswings in Core Inflation (Inflation excluding food and transportation prices), as pointed out by Hisham in this post. I will now summarise why the statistics cited by Priscilla understates the reality that we are in fact affected by inflation at this moment and would like to point out empirical inconsistencies with her explanation for "stagnant wages."





On Catching Up with Purchasing Power
It would be misleading to generalise the purchasing power of citizens between nations with the purchasing power of the residents between major cities of nations.Major cities become so because they tend to specialise in important economic activities that affords their residents a higher standard of living compared to their counterparts in other parts of the country.Confounded data leads to false conclusion. It is conceivable that in a country afflicted with extreme regional economic inequality that residents living in major cities tend to have a higher standard of living compared to their counterparts in other countries and the majority of their fellow citizens in other regions. As an analogy suppose you were asked to investigate the educational level of countries. If we select the highest-ranked universities as comparison groups the United States of America would be leading other countries, but does that mean that on average Americans have the highest standard of education in the world? According to OECD, the answer is no. Likewise we cannot generalise that because the residents in Kuala Lumpur have coped well with inflation by achieving purchasing power parity with other advanced cities, Malaysians as a whole are doing well.





Empirical inconsistency for the explanation of stagnant wages
Stagnant Wages is explained in the op-ed by invoking labour theory with  "an over-supply of labour." This is achieved by looking at 2 groups, the low-skilled labours and the market for "fresh-graduates or junior executives." The hypothesis required to support the phenomenon observed with the former group is rejected by empirical data (elaborated below) while the latter group would be more apt as evidence for "inadequate training" rather than the effect of the over-abundance of junior executives. 


Implicit Xenophobic and protectionist tendencies affect public and economic policies much more than we are aware of. Malaysians in particular are prone to the heuristics of blaming immigrants for unemployment and stagnant wage issues. Arguments like "(The Willingness of immigrants to accept lower wages) undermines the job opportunities for many of the “low-income to hardcore poor” Malaysians who do not mind taking on these jobs as it may be their only opportunity to earn a living" sound intuitively appealing, but it is worth knowing that economists analysing the impact of immigrant inflows to the labour market in the United States of America have failed to find statistically significant net impact of immigrants on the net job growth of American-born workers. 


However in rejecting the explanation the onus is upon me to show why it is false. In order to confidently express that immigrants do not affect the job prospects of local workers we would ideally want a study that studies the net impact on productivity after controlling for all factors except for the flow of immigrants. A study by Giovanni Peri (summary here) does just this, and concludes that

"Data show that, on net, immigrants expand the U.S. economy’s productive capacity, stimulate investment, and promote specialization that in the long run boosts productivity. Consistent with previous research, there is no evidence that these effects take place at the expense of jobs for workers born in the United States."
Of course the data is drawn from the United States of America, yet there is no reason to assume that the same explanation cannot be applied in Malaysia.

P/S Of course a high nominal inflation would not be a problem if wages adjust to keep real inflation at bay. However, resentment and disapproval on the way inflation is handled by the authorities even if real inflation remains at zero is possible, since people have a bias towards nominal evaluation.
For further reading on the matter see "Money Illusion" published in The Quarterly Journal of Economics, 112:2,341-74 by Eldar Shafir,Peter Diamond and Amos Tversky.