June 19, 2011

## TikZ for economists: A how-to guide with examples

Below is a guide I created to assist economists in quickly creating economics diagrams using the package TikZ in LaTeX.

Thoughts, comments, ideas? Let me know; I’m always appreciative of feedback. Correspondence via e-mail can be directed to kevingoulding [at] gmail {dot} com.

Tags: , ,
June 17, 2011

## TikZ diagrams for economists: A normal pdf with shaded area.

I have been dabbling with the TikZ package to create some diagrams relevant to a first year microeconomics course. The following diagram of the probability density function (pdf) of a normal distribution may be useful to others wishing to integrate similar diagrams into their LaTeX documents or Beamer presentations. To use, insert the following code anywhere you like within a .tex document (you must include \usepackage{tikz} in your header):

## The Cumulative Density of $y$ #### INSERT INTO .TEX DOCUMENT

\begin{tikzpicture}
% define normal distribution function 'normaltwo'
\def\normaltwo{\x,{4*1/exp(((\x-3)^2)/2)}}

% input y parameter
\def\y{4.4}

% this line calculates f(y)
\def\fy{4*1/exp(((\y-3)^2)/2)}

% Shade orange area underneath curve.
\fill [fill=orange!60] (2.6,0) -- plot[domain=0:4.4] (\normaltwo) -- ({\y},0) -- cycle;

% Draw and label normal distribution function
\draw[color=blue,domain=0:6] plot (\normaltwo) node[right] {};

% Add dashed line dropping down from normal.
\draw[dashed] ({\y},{\fy}) -- ({\y},0) node[below] {$y$};

\draw (-.2,2.5) node[left] {$f_Y(u)$};
\draw (3,-.5) node[below] {$u$};

\draw[->] (0,0) -- (6.2,0) node[right] {};
\draw[->] (0,0) -- (0,5) node[above] {};

\end{tikzpicture}


## The Probability of $u$ Falling Between $x$ and $y$ #### INSERT INTO .TEX DOCUMENT

\begin{tikzpicture}
% define normal distribution function 'normaltwo'
\def\normaltwo{\x,{4*1/exp(((\x-3)^2)/2)}}

% input x and y parameters
\def\y{4.4}
\def\x{3.4}

% this line calculates f(y)
\def\fy{4*1/exp(((\y-3)^2)/2)}
\def\fx{4*1/exp(((\x-3)^2)/2)}

% Shade orange area underneath curve.
\fill [fill=orange!60] ({\x},0) -- plot[domain={\x}:{\y}] (\normaltwo) -- ({\y},0) -- cycle;

% Draw and label normal distribution function
\draw[color=blue,domain=0:6] plot (\normaltwo) node[right] {};

% Add dashed line dropping down from normal.
\draw[dashed] ({\y},{\fy}) -- ({\y},0) node[below] {$y$};
\draw[dashed] ({\x},{\fx}) -- ({\x},0) node[below] {$x$};

\draw (-.2,2.5) node[left] {$f_Y(u)$};
\draw (3,-.5) node[below] {$u$};

\draw[->] (0,0) -- (6.2,0) node[right] {};
\draw[->] (0,0) -- (0,5) node[above] {};

\end{tikzpicture}


The TikZ code snippet above is meant to be dropped into a .tex document and work without any further “tinkering”. Please let me know if this is not the case!

Tags: , ,
June 17, 2011

## TikZ diagrams for economists: An excise tax

I have been dabbling with the TikZ package to create some diagrams relevant to a first year microeconomics course. The following diagram of an excise tax may be useful to others wishing to integrate similar diagrams into their LaTeX documents or Beamer presentations. To use, insert the following code anywhere you like within a .tex document (you must include \usepackage{tikz} in your header):

#### INSERT INTO .TEX DOCUMENT

%                         TikZ code: An excise tax

\begin{tikzpicture}[domain=0:5,scale=1,thick]
\usetikzlibrary{calc}	                             %allows coordinate calculations.
\usetikzlibrary{decorations.pathreplacing}           %allows drawing curly braces.

% Define linear parameters for supply and demand
\def\dint{4.5}		%Y-intercept for DEMAND.
\def\dslp{-0.5}		%Slope for DEMAND.
\def\sint{1.2}		%Y-intercept for SUPPLY.
\def\sslp{0.8}  	%Slope for SUPPLY.

\def\tax{1.5}		%Excise (per-unit) tax

% Define Supply and Demand Lines as equations of parameters defined above.
\def\demand{\x,{\dslp*\x+\dint}}
\def\supply{\x,{\sslp*\x+\sint}}
\def\demandtwo{\x,{\dslp*\x+\dint+\dsh}}
\def\supplytwo{\x,{\sslp*\x+\sint+\ssh}}

% Define coordinates.
\coordinate (ints) at ({(\sint-\dint)/(\dslp-\sslp)},{(\sint-\dint)/(\dslp-\sslp)*\sslp+\sint});
\coordinate (ep) at  (0,{(\sint-\dint)/(\dslp-\sslp)*\sslp+\sint});
\coordinate (eq) at  ({(\sint-\dint)/(\dslp-\sslp)},0);
\coordinate (dint) at (0,{\dint});
\coordinate (sint) at (0,{\sint});

\coordinate (teq) at  ({(\sint+\tax-\dint)/(\dslp-\sslp)},0); %quantity
\coordinate (tep) at  (0,{(\sint+\tax-\dint)/(\dslp-\sslp)*\sslp+\sint+\tax}); %price
\coordinate (tint) at  ({(\sint+\tax-\dint)/(\dslp-\sslp)},{(\sint+\tax-\dint)/(\dslp-\sslp)*\sslp+\sint+\tax}); %tax equilibrium

\coordinate (sep) at (0,{\sslp*(\sint+\tax-\dint)/(\dslp-\sslp)+\sint});
\coordinate (sen) at ({(\sint+\tax-\dint)/(\dslp-\sslp)},{\sslp*(\sint+\tax-\dint)/(\dslp-\sslp)+\sint});

% DEMAND
\draw[thick,color=blue] plot (\demand) node[right] {$P(q) = -\frac{1}{2}q+\frac{9}{2}$};

% SUPPLY
\draw[thick,color=purple] plot (\supply) node[right] {Supply};

% Draw axes, and dotted equilibrium lines.
\draw[->] (0,0) -- (6.2,0) node[right] {$Q$};
\draw[->] (0,0) -- (0,6.2) node[above] {$P$};
\draw[decorate,decoration={brace},thick]  ($(sep)+(-0.8,0)$) -- ($(tep)+(-0.8,0)$) node[midway,below=-8pt,xshift=-18pt] {tax};

\draw[dashed] (tint) -- (teq) node[below] {$Q_T$};
\draw[dashed] (tint) -- (tep) node[left] {$P_d$};
\draw[dashed] (sen) -- (sep) node[left] {$P_s$};

\end{tikzpicture}


The TikZ code snippet above is meant to be dropped into a .tex document and work without any further “tinkering”. Please let me know if this is not the case!

Tags: , ,
June 11, 2011

## TikZ diagrams for economists: A price ceiling

I have been dabbling with the TikZ package to create some diagrams relevant to a first year microeconomics course. The following diagram of a price ceiling may be useful to others wishing to integrate similar diagrams into their LaTeX documents or Beamer presentations. To use, insert the following code anywhere you like within a .tex document (you must include \usepackage{tikz} in your header):

#### INSERT INTO .TEX DOCUMENT

\begin{tikzpicture}[domain=0:5,scale=1,thick]
\usetikzlibrary{calc}	%allows coordinate calculations.

%Define linear parameters for supply and demand
\def\dint{4.5}			%Y-intercept for DEMAND.
\def\dslp{-0.5}			%Slope for DEMAND.
\def\sint{1.2}			%Y-intercept for SUPPLY.
\def\sslp{0.8}  		%Slope for SUPPLY.

\def\pfc{2.5}			%Price floor or ceiling

\def\demand{\x,{\dslp*\x+\dint}}
\def\supply{\x,{\sslp*\x+\sint}}

% Define coordinates.
\coordinate (ints) at ({(\sint-\dint)/(\dslp-\sslp)},{(\sint-\dint)/(\dslp-\sslp)*\sslp+\sint});
\coordinate (ep) at  (0,{(\sint-\dint)/(\dslp-\sslp)*\sslp+\sint});
\coordinate (eq) at  ({(\sint-\dint)/(\dslp-\sslp)},0);
\coordinate (dint) at (0,{\dint});
\coordinate (sint) at (0,{\sint});
\coordinate (pfq) at  ({(\pfc-\dint)/(\dslp)},0);
\coordinate (pfp) at  ({(\pfc-\dint)/(\dslp)},{\pfc});
\coordinate (sfq) at  ({(\pfc-\sint)/(\sslp)},0);
\coordinate (sfp) at  ({(\pfc-\sint)/(\sslp)},{\pfc});

% DEMAND
\draw[thick,color=blue] plot (\demand) node[right] {$P(q) = -\frac{1}{2}q+\frac{9}{2}$};

% SUPPLY
\draw[thick,color=purple] plot (\supply) node[right] {Supply};

% Draw axes, and dotted equilibrium lines.
\draw[->] (0,0) -- (6.2,0) node[right] {$Q$};
\draw[->] (0,0) -- (0,6.2) node[above] {$P$};

%Price floor and ceiling lines
\draw[dashed,color=black] plot (\x,{\pfc}) node[right] {$P_c$};
\draw[dashed] (pfp) -- (pfq) node[below] {$Q_d$};
\draw[dashed] (sfp) -- (sfq) node[below] {$Q_s$};

\draw[->,baseline=5] ($(0,{\pfc})+(-1.5,0.7)$) node[label= left:Price Ceiling] {} -- ($(0,{\pfc})+(-.1,0.1)$);

\end{tikzpicture}

Tags: , ,