Sunday, January 28, 2018

Understanding Basic structure of SAM (Social Accounting Matrix)

Understanding the interaction and transfers between different factors of production, production activities and institutions (households, governments and corporate sector) is imperative in order to completely grasp the concept of  macro economic dynamics. The interaction  can be illustrated with the help of Social Accounting Matrix (SAM).

In this post we create SAM  and then attempt to create SAM multiplier. SAM is a matrix representation of national account for a single year and it sketches transactions that take place within an economy/ country. SAM is a squared matrix in which each 'row' and 'column' is called account, and each cell in the matrix represents circular flow from column to  row accounts. For example: While accounting an expenditure of households on commodities, we record the household expenditure in household 'Column' and value of consumed commodities in commodities 'Row'

(Note that total expenditure on commodities is equal to value of total commodities, which  complements the double entry accounting requirement, that the total expenditure is equal to total revenue). 

In SAM we distinguish entities between 'Activities' and 'Commodities'. Activities are those entities which produce commodities sold in an economy. This distinction is important because there are different commodities, and sometimes a commodity can be produced by more than one kind of activity. Similarly one activity can produce more than one kind of commodity. In our illustration we denote activity with '_a' and commodity with '_c'


 Activities makes use of intermediate commodities and factors of production to produce final commodities and services (C1). The factors are paid, wages (for labor), rent (for capital) and profits (to firm), so the value added 'cell' (R1C3) appears in SAM.  It is important to note that the sum of activities (C1 R8) is Gross Output, and is equal to activity income in R1.

Commodities (R2) are either imported or domestically supplied. (R1 C2)  Further there are sales taxes and import tariffs in products (R5 C2). As total supply is accounted on market value, inclusion of sales taxes and import tariff is important. Sum of commodities produced is total supply (R8 C2) in an economy which is equals to Total demand (R2) . The total demand (R2 C8)  is sum of demand for intermediate commodities (by each activities), consumption spending on commodities (by households), recurrent spending by government, investment demand and export earnings.

Factor payments (R4 C3) made to households for supply of labor and capital is the total factor spending (R8 C3) in the economy. The payment made to factor is equal to the total factor income (R3 C8)

Similarly household spends on consumption (R2 C4) and direct taxes (R5 C4), the remaining income is then saved (or dissaved if expenditure exceeds income) (R6 C4).

Government spends on normal recurrent activities (R2 C5) and social transfers (R4 C5), and if Government revenue earned from sales taxes, direct taxes)  is greater/less than expenditure then  fiscal/deficit (R6 C5) surplus occurs.

Rest of the world shows foreign exchange inflow/outflows, that is why export earnings, foreign remittances, foreign grants and loans and current account balance are included in C7. The summation of rest of the world gives Foreign exchange inflow (R8 C7).

Wednesday, January 10, 2018

Statistical Properties of OLS

Our statistical model is restricted to linearity  (in parameters ).

The model we have is $y={{\beta }_{1}}+{{\beta }_{2}}X+\varepsilon$

As stated in the earlier post, we can stack everything together, and write the equation (no matter how many explanatory variables we have), in the matrix form: \(y=x\beta +\varepsilon\).  The matrix representation shows that the regression analysis is conditional upon value of 'x'

'Y' and 'X' are observed, 'beta' is fixed unknown parameter and '$\varepsilon $' is observed random term . 


The reason we use OLS is that, under assumptions A1- A7 of the classical linear regression model, the OLS have several desirable statistical properties. This post examines these desirable statistical properties of OLS under seven assumptions:

Seven assumptions of the model:

A1: Fixed Regressor: It means that all the elements of matrix 'x' with dimension N times K are fixed (or we can say it is non-stochastic/non random/deterministic). Further, assumption also requires that N must be greater than K  (N is number of observations and K is number of co-efficient), and matrix N*K is a full rank (Invertible).

Violations of these two conditions can have errors in variables in following forms:
a) Auto Regression
b) Simultaneous Equation  
c) Perfect Multicollinearity 


A2: Random Disturbance zero Mean: It means that expectation of random term is equal to zero or
$E\left[ \varepsilon  \right]=0\text{ or }E\left[ \varepsilon  \right]=0$. 




A3: Homoscedasticity: (Homo= Same and Scedas= Spread):  It means that variance of the error terms is equal to sigma square. $Var({{\varepsilon }_{i}})=\text{ E(}\varepsilon {{\varepsilon }^{T}})={{\sigma }^{2}}$.

The variance  is similar across range of values of independent variable.

Violation of A3 leads to Heteroscedasticity : It means that the variability of variable is unequal across the range of values.

We can use assumptions A2 $E\left[ \varepsilon  \right]=0\text{ or }E\left[ \varepsilon  \right]=0$  with A3 to get more insight regarding the property  $Var({{\varepsilon }_{i}})=\text{ E(}\varepsilon {{\varepsilon }^{T}})={{\sigma }^{2}}$  :



Step1 is formula of variance (actual subtract to mean)
Step2 is rule of decomposition 
Step 3 we replace the value of expectation of $E(\varepsilon )$from A2: which states that $E\left[ \varepsilon  \right]=0\text{ or }E\left[ \varepsilon  \right]=0$

A4:  No Auto-correlation: The Covariance between epsilon(i) and epsilon (j) is zero or $Cov({{\varepsilon }_{i}}{{\varepsilon }_{j}})=0$

In other words, error of 'i'th variable and 'j' variable doesn't change together.

A5: Constant Parameters : This means ${{\beta }_{k*1}}\text{ and }\varepsilon $ are fixed and unknown

A6: Linear Model : As stated earlier, it is linear in parameter. Basically it is saying that 'y' is generated through a process $y={{\beta }_{1}}+{{\beta }_{2}}X+\varepsilon$ (DGP= Data generating process)

A7: Normality: The distributions of the error term '$\varepsilon $' is normal

Now if we combine assumptions A2 (Random Distribution) +A3 (Homoscedasticity) +A4 (No Auto-Correlation)+A7 (Normality) we get '$\varepsilon \sim N(0\text{ , }{{\sigma }^{2}}{{I}_{N*N}})$'


In Econometrics; the assumptions are just like a catalogue , one has to refer the catalogue and if there is any violation (of the assumptions) then we must treat the violation with specific technique.

Friday, January 5, 2018

Orthogonality and Geometric representation of OLS solution

You will have to go through part  Deriving OLS with Matrices  as prerequisite to understand this post:

From first order condition we have:

\[\begin{align} & \frac{\partial S}{\partial b}=2{{x}^{T}}xb-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}}=0 \\ & or\text{ }2{{x}^{T}}(y-xb)=0 \\ & or\text{ }{{x}^{T}}(y-xb)=0 \\ \end{align}\]
Here: \((y-xb)=e\text{ }\left( Residual \right)\)
So, \(\text{ }{{x}^{T}}e=0\)

Note that \({{x}^{T}}e=0\) is the condition of orthogonality 

What is Orthogonality ?

When conducting econometric or statistical analysis, independent variables that affect particular dependent variable are said to be orthogonal if they are uncorrelated. Orthogonality is a condition when two vectors intersect each other in a right angle. 
 In above illustration 'x' independent variable is orthogonal on 'e' residual

Geometric representation of 'OLS' solution 

We have residual 'e' represented as difference between actual and predicted value. So y (actual) -xb (predicted y) which is equal to 'e' can be written as:

\(\begin{align} & e=y-xb=y-x{{({{x}^{'}}x)}^{-1}}{{x}^{'}}y \\ & =(I-x{{({{x}^{'}}x)}^{-1}}{{x}^{'}})y \\ \end{align}\)

Remember we derived value of 'b' from OLS solution in previous post

Let M = \(\begin{align} &(I-x{{({{x}^{'}}x)}^{-1}}{{x}^{'}}) \\ \end{align}\) 

So the expression becomes 'My',  known as operator

Further we know that $\hat{y}=xb={{({{x}^{'}}x)}^{-1}}{{x}^{'}}y$
Let H= ${{({{x}^{'}}x)}^{-1}}{{x}^{'}}$

So the expression becomes 'Hy', known as 'Hat' matrix or Projection matrix



Note that e ='My' is perpendicular on y(hat)= 'Hy' line which has the projection matrix made of x

Tuesday, January 2, 2018

Deriving OLS with Matrices

In Econometric and statistics, ordinary least squares (OLS) or linear least squares is a method for estimating the unknown parameters($\beta$)  in a linear regression model. The goal is to minimize the differences ($\varepsilon \text{ or e}$) between the observed values and predicted values with the use of linear approximation. In this post i make an effort to derive the OLS solution ($\beta$) with Matrices

We know that Simple OLS regression looks like $y={{\beta }_{1}}+{{\beta }_{2}}X+\varepsilon$. Suppose we have ‘n’ numbers of observations and ‘k’ numbers of explanatory variables. If we convert the equation into matrix form, it looks like:



From above representation we can infer that the size of Y (Dependent variable) is N by 1, size of X (Independent variable) is N by K and size of e  (errors of prediction) is N by 1. This gives us a clue that size of Beta (B) is K by 1 i.e  Beta has K row and 1 column.

The whole purpose of this post is to derive the beta from the structure by minimizing the square of residuals  in matrix notation 

(Step: 1) Because we can stack everything together, we can write the equation (no matter how many explanatory variables we have) in the form: \[y=x\beta +\varepsilon\].

The equation in-turn can be written as: \[\text{y=xb+e}\] Where, e=Residual and XB is OLS estimator.

(Step 2) We know that the error term 'e' is  \[\begin{align} & e=y-{{y}^{\wedge }}=y-xb \\ & \\ \end{align}\] (y is the fitted value and y^ is the predicted, and we minimize sum of residual squares).

Note: ‘e’ is a scalar and it has N by 1 dimension matrix, and 'e' transpose has 1 by N dimension.

So the square of residuals is ${{e}^{2}}={{e}^{T}}*e$, and it has 1 by 1 dimension.

(Step 3) We represent minimized sum of square residuals as  $Minimize\text{ S(b)= }\sum{{{e}_{i}}^{2}}={{e}^{T}}*e$ , and after we include the value of e and e(Transpose) it looks like: $={{[y-xb]}^{T}}*[y-xb]$

Note: ($e^{T}={{[y-xb]}^{T}}and $ e= [y-xb])

We need to solve this further with the help of matrix rule which states that: ${{(A+B)}^{T}}={{A}^{T}}+{{B}^{T}}$ and ${{(A*B)}^{T}}={{B}^{T}}*{{A}^{T}}$

(Step 4) Working out with the rule, we progress further and expand ((Step 3) as follows: $\begin{align} & =[{{y}^{T}}-{{x}^{T}}{{b}^{T}}][y-xb] \\ & ={{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb \\ \end{align}$

This means that sum of square residuals $S={{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb$

(Step 5) Now, inorder to minimize the sum of square residuals we take first order derivative with respect to 'b'

\[\frac{\partial S(b)}{\partial b}=\frac{\partial ({{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb)}{\partial b}\]

There is a rule for derivatives of matrix which states that:

\[(i)\frac{\partial Ax}{\partial x}={{A}^{'}}\text{ ; (ii)}\frac{\partial {{x}^{'}}Ax}{\partial x}=2Ax\text{ (If  }\!\!'\!\!\text{ A }\!\!'\!\!\text{  is symetric) and = (}{{\text{A}}^{'}}+A)x\text{ (If  }\!\!'\!\!\text{ A }\!\!'\!\!\text{  is not symetric)}\] 
Symmetric: If A is equal to A (Transpose) then A is symmetric.

(Step 6) First order condition leaves us with:
 \[\begin{align} & \frac{\partial S(b)}{\partial b}=\frac{\partial ({{y}^{T}}y-{{b}^{T}}{{x}^{T}}y-{{y}^{T}}xb+{{b}^{T}}{{x}^{T}}xb)}{\partial b} \\ & \frac{\partial S(b)}{\partial b}=0-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}}+2{{x}^{T}}xb \\ & \frac{\partial S(b)}{\partial b}=2{{x}^{T}}xb-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}} \\ \end{align}\]

Now, we make the term equal to zero as per first order condition of minimization to get expression for 'b'.
\[\begin{align} & 2{{x}^{T}}xb-{{x}^{T}}y-{{({{y}^{T}}x)}^{T}}=0 \\ & or\text{ }2{{x}^{T}}xb-{{x}^{T}}y-{{x}^{T}}y=0 \\ & or\text{ }2{{x}^{T}}xb={{x}^{T}}y+{{x}^{T}}y \\ & or\text{ }2{{x}^{T}}xb=2{{x}^{T}}y \\ & or\text{ }{{({{x}^{T}}x)}^{-1}}{{x}^{T}}xb={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y \\ & or\text{ }Ib={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y \\ & \therefore b={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y \\ \end{align}\]

(Step 7) Now we check the second order condition of minimization, where the result must be greater than zero:


\[\frac{{{\partial }^{2}}S(b)}{\partial b\partial {{b}^{'}}}=2{{x}^{T}}x\text{ (The expression is a Positive definite)}\]

Since $2{{x}^{T}}x$ is greater than zero, we confirm that the expression derived for beta i.e $b={{({{x}^{T}}x)}^{-1}}{{x}^{T}}y$ shall give value of coefficient that minimizes the sum of the squared errors of prediction when y is regressed on x.

Next post will focus on OLS solution properties (With Matrices)