\documentclass[12pt]{article} \usepackage{amssymb} \usepackage{graphicx} %\usepackage[dcucite]{harvard} \usepackage{amsmath} \usepackage{color} \usepackage{setspace} \usepackage{booktabs} \usepackage{hyperref} \usepackage[T1]{fontenc} \usepackage{threeparttable} \usepackage{array} \usepackage{longtable} \usepackage{subcaption} \usepackage{adjustbox} \usepackage{tikz} \usetikzlibrary{decorations.pathreplacing} \usepackage{natbib} %\usepackage{apacite} \usepackage{indentfirst} \usepackage{tikz} \usetikzlibrary{arrows,shapes,positioning,shadows,trees} \usepackage[table]{colortbl}% http://ctan.org/pkg/xcolor \tikzset{ basic/.style = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle}, root/.style = {basic, rounded corners=2pt, thin, align=center, fill=teal!50, text width=20em}, level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=teal!35, text width=6.5em}, level 3/.style = {basic, thin, align=center, fill=teal!10, text width=6.5em} } \setlength{\topmargin}{0.1in} \setlength{\headheight}{0in} \setlength{\headsep}{0in} \setlength{\topskip}{0in} \setlength{\textheight}{8.5in} \setlength{\oddsidemargin}{0in} \setlength{\evensidemargin}{0in} \setlength{\textwidth}{6.5in} \newcommand\inv[1]{#1\raisebox{1.15ex}{$\scriptscriptstyle-\!1$}} \usepackage{listings} \usepackage{xcolor} \usepackage{amsmath} \usepackage{natbib} \usepackage{comment} \usepackage{xr-hyper} \PassOptionsToPackage{hidelinks}{hyperref} \usepackage{graphicx} \usepackage{appendix} \usepackage{minted} \newminted{python} \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5} \definecolor{codepurple}{rgb}{0.58,0,0.82} \definecolor{backcolour}{rgb}{0.95,0.95,0.92} \lstdefinestyle{mystyle}{ backgroundcolor=\color{backcolour}, commentstyle=\color{codegreen}, keywordstyle=\color{magenta}, numberstyle=\tiny\color{codegray}, stringstyle=\color{codepurple}, basicstyle=\ttfamily\footnotesize, breakatwhitespace=true, breaklines=true, captionpos=b, keepspaces=true, numbers=left, numbersep=5pt, showspaces=false, showstringspaces=false, showtabs=true, tabsize=2 } \lstset{style=mystyle} \makeatletter \setlength{\@fptop}{0pt} \makeatother \begin{document} \title{PyPE: A new platform for analyzing trade policy with partial equilibrium models\vspace{0.5in}% } \author{Saad Ahmad, Tyler Duan and Christopher Montgomery\thanks{U.S. International Trade Commission.\newline Contact emails: saad.ahmad@usitc.gov, tyler.duan@usitc.gov,chris.montgomery@usit.gov}} \date{\vspace{1.5in}% \today} \thispagestyle{empty} { % set font to helvetica (arial) to make it 508-compliant \fontfamily{phv}\selectfont \begin{center} {\Large \textbf{PyPE: A new platform for analyzing trade policy with partial equilibrium models}\\} \vspace{0.75in} {\Large Saad Ahmad, Tyler Daun and Christopher Montgomery} \\ \vspace{0.75in} \vspace{0.75in} {\large ECONOMICS WORKING PAPER SERIES}\\ Working Paper 2022--05--C \\ \vspace{0.5in} U.S. INTERNATIONAL TRADE COMMISSION \\ 500 E Street SW \\ Washington, DC 20436 \\ \vspace{0.25in} May 2022 \end{center} \vfill \noindent Office of Economics working papers are the result of ongoing professional research of USITC Staff and are solely meant to represent the opinions and professional research of individual authors. These papers are not meant to represent in any way the views of the U.S. International Trade Commission or any of its individual Commissioners. Working papers are circulated to promote the active exchange of ideas between USITC Staff and recognized experts outside the USITC and to promote professional development of Office Staff by encouraging outside professional critique of staff research. Please address correspondence to saad.ahmad@usitc.gov or christopher.montgomery@usitc.gov. \newpage \thispagestyle{empty} % remove headers, footers, and page numbers from cover page \begin{flushleft} PyPE: A new platform for analyzing trade policy with partial equilibrium models \\ Saad Ahmad, Tyler Daun and Christopher Montgomery \\ Office of Economics Working Paper 2022--05--C\\ May 2022\\~\\ \end{flushleft} \vfill \begin{abstract} \noindent We introduce a new Python package PyPE for developing and conducting partial equilibrium (PE) analysis of trade policies. PyPE offers practitioners a flexible framework to select and combine different trade model features to determine the impact of select policies on a particular market or industry. With a user-friendly interface, PyPE allows users to run model simulations and report results with only a few lines of code. Interested users are also encouraged to assist with PyPE development by proposing or constructing new model features that can be incorporated within the package. \end{abstract} \vfill \begin{flushleft} Saad Ahmad, Office of Economics\\ \href{mailto:saad.ahmad@usitc.gov}{saad.ahmad@usitc.gov}\\ \vspace{0.25in} Tyler Daun, Office of Economics\\ \href{mailto:tyler.daun@usitc.gov}{tyler.daun@usitc.gov}\\ \vspace{0.25in} Christopher Montgomery, Office of Economics\\ \href{mailto:christopher.montgomery@usitc.gov}{christopher.montgomery@usitc.gov}\\ \vspace{0.75in} \end{flushleft} } % end of helvetica (arial) font \clearpage \newpage \doublespacing \setcounter{page}{1} \section{Introduction} Partial equilibrium (PE) models are often used to analyze the economic effects from changes in trade policy. In contrast to general equilibrium economy-wide models, PE models can be narrowly tailored to examine the impact of the policy changes on specific industries and sectors. With their practical data requirements, PE models represent a convenient option for conducting ex-ante quantification of both tariff and non-tariff policy changes. Some recent policy applications of PE models include the effect of stricter USMCA Rules of Origin on the auto sector \citep{USITC2019}; the impact of CBERA preferences on U.S. domestic industries \citep{USITC2021a}; and the impact on the U.S. domestic raspberries processing industry from higher imports of raspberries \citep{USITC2021b}.\footnote{Reports published by the U.S. International Trade Commission are available here: \url{https://www.usitc.gov/commission_publications_library}.} In this paper, we introduce a new Python package PyPE that allows for the development and execution of PE models analyzing the impact of trade policy. PyPE offers a flexible framework for model developers to create new types of PE models. Our framework allows model developers to select and combine pre-codified model features that are stored and validated within the PyPE package. Likewise, interested users are encouraged to assist with PyPE development by proposing or constructing new model features to be stored within the package. Existing features and future updates will be designed to be agnostic to the number of firms in a market, allowing completed models to execute given any number of user-specified firms or products. In addition to tools for model developers, PyPE offers an intuitive, user-friendly interface for running model simulations and reporting results. With PyPE, model users can supply their own market data to a flexible model of their choosing in less than a few simple lines of Python code. PyPE also reports key model results in an intuitive, easy to access manner. Rest of the paper is organized as follows. Section \ref{sec:theory} covers the theoretical foundation of the PyPE models, including the key equations for each of the included models of competition. Section \ref{sec:frame} describes the structure of the PyPE package. Section \ref{sec:demo} shows a demonstration of PyPE using sample inputs and compares results of the different types of competition. Section \ref{sec:conclude} concludes with a brief discussion of future plans for the PyPE package. \section{Theory}\label{sec:theory} \subsection{Demand} The suite of PE models currently available in PyPE is built on the assumption that consumers have a love of variety and prefer to consume a little of each product variety in the market. Product varieties in the market can be differentiated either at the country level, as in \citet{armington1969}, or at the firm level following \citet{Krugman1979} and other more recent trade models. We further assume a Constant Elasticity of Substitution (CES) demand framework so that consumers switch between product varieties at a constant rate of $\sigma$, the elasticity of substitution.\footnote{This framework can be easily extended to a nested CES demand structure so that consumers in the first stage aggregate over a user-defined subset of varieties in the industry and a composite of the varieties excluded from the subset. In the second stage, consumers aggregate over the subset of varieties that comprise the composite in the first stage.} Let $i$ represent a distinct source supplying goods to the domestic market. To simplify the subsequent discussions, we assume there are only 3 sources of goods in the market: domestic suppliers that face no tariffs (d), foreign suppliers whose products are subject to the new tariffs (s), and foreign suppliers whose products are not subject to the new tariffs (n).\footnote{The number of sources in PyPE is flexible and user can input as many sources as needed.} Under CES demand, domestic consumers thus face the following utility maximization problem: \begin{equation} U=\left(\sum_{i}m_{i}b_{i}q_{i}^{\frac{\sigma-1}{\sigma}}\right)^{_{\frac{\sigma}{\sigma-1}}}\;\;s.t.\quad\sum_{i}m_{i}p_{i}(1+\tau_{i})q_{i}=E \end{equation} For each source $i\in(d,s,n)$, $p_{i}$ is the producer's price and $q_{i}$ is the quantity demanded of the good in the domestic market. Consumers pay an ad valorem tariff rate $\tau_{i}$ for all goods coming from source $i$ with $\tau_{d}=0$. $b_{i}$ is an exogenous parameter capturing asymmetries in consumer preferences across sources while $m_{i}$ is the mass of firms producing the different varieties of the good in each source country. Note that under an Armington framework of trade, we just assume that countries rather than firms are supplying the different product varieties. Lastly, $E$ is the level of aggregate expenditure in the domestic economy for this good. If we let $\beta_{i}=b_{i}^{\sigma}$, then maximizing utility subject to the budget constraint gives us the following consumer demand from each source country: \begin{equation} q_{i}=\beta_{i}Ep_{i}^{-\sigma}(1+\tau_{i})^{-\sigma}P^{\sigma-1} \end{equation} \begin{equation} P=\left(\sum_{i}m_{i}\beta_{i}[p_{i}(1+\tau_{i})]^{1-\sigma}\right)^{\frac{1}{1-\sigma}} \end{equation} Note $P$ is the CES price index for all the varieties consumed in home country. In order to capture aggregate demand effects in PyPE, we take $\theta<0$ to be the price elasticity of total demand and $k$ an aggregate demand parameter such that: \begin{equation} E=kP^{\theta+1} \end{equation} \begin{equation} q_{i}=k\beta_{i}p_{i}^{-\sigma}(1+\tau_{i})^{-\sigma}P^{\sigma+\theta} \end{equation} \begin{equation} V_{i}=m_{i}k\beta_{i}p_{i}^{1-\sigma}(1+\tau_{i})^{1-\sigma}P^{\sigma+\theta} \end{equation} Here $V_{i}$ represents the total home sales from source $i$. We next set initial consumer prices from all source countries to $1$ and normalize the number of firms and preferences by their domestic counterparts such that $ m_{d}\beta_{d}=1$. Using the initial sales for each source in the domestic market, we get the following calibration: \begin{equation} m_{s}\beta_{s}=\frac{V_{s}}{V_{d}} \end{equation} \begin{equation} m_{r}\beta_{r}=\frac{V_{r}}{V_{d}} \end{equation} \begin{equation} k=\frac{V_{d}}{\left[1+m_{s}\beta_{s}+m_{r}\beta_{r}\right]^{\frac{\theta+\sigma}{1-\sigma}}} \end{equation} Thus, initial revenues in the domestic market along with the elasticity parameters are all that is required to recover the other structural parameters of the CES demand.\footnote{The above calibration allows us to recover only $m_{i}\beta_{i}$ for each source $i$ with the number of firms $m_{i}$ indeterminate. Thus, more information would be needed if we want to use the underlying PE framework to also capture firm entry or exit from the policy shock.} \subsection{Supply under Monopolistic Competition} To model supply under monopolistic competition, we assume that in each source country $i\in(d,s,n)$, there is a mass $m_{i}$ of homogeneous firms each producing a unique variety. To simplify the modeling, we do not allow for firm entry/exit so that the number of firms is held fixed in the PE simulations, restricting the analysis to only the short-run effects on market participants from policy changes. Following \citet{Krugman1979}, all firms in source $i$ face constant marginal costs $c_{i}$ to produce their variety. A continuum of monopolistic competitive firms along with the CES demand framework implies that each firm's optimal price will be given as a constant markup over their marginal costs: \begin{equation} p_{i}=\frac{\sigma}{\sigma-1}c_{i} \end{equation} With constant markups, there will be a 100\% pass-thru of tariffs with domestic consumers paying $(1+\tau_{i})p_{i}$ for all varieties produced in country $i$. A 100\% pass-thru means that solving for the new equilibrium from the demand side is sufficient for determining the effects of a tariff change. In practice, this means solving the system of equations given by demand from each source $i$ along with the CES price index as tariffs go from $\tau^{0}_{i}$ to $\tau^{1}_{i}$. %PyPE relies on a non-linear solver from the SciPy library to compute the new equilibrium Together with consumer prices and quantities, we can also use the monopolistic competition framework to determine changes in firm profits. Besides variable input costs, we assume that firms incur a fixed cost $f_{i}$ to sell to the domestic market. Thus a firm\textquoteright s net profits from selling to the home market are computed as: \[ \pi_{i}=p_{i}q_{i}-c_{i}q_{i}-f_{i} \] It can be shown that a firm's operating profit, revenue minus variable costs, are a fixed proportion of its revenue.\footnote{See \citet{Ahmad19} for additional details on how to compute changes in profits in PE models with monopolistic competition.} \subsection{Supply under Perfect Competition} Supply under perfect competition is characterized by many firms (specifically, an infinite number of infinitely small firms) all selling exactly identical products. Individual firms have no pricing power and take the market price as given when choosing how much to produce. Given these characteristics, it is often convenient to return to an Armington framework of trade so that goods are differentiated by source country, rather than firms. A number of functional forms are available in PyPE for modeling supply under perfect competition. The canonical treatment in PE analysis is to assume isoelastic supply curves so that the price elasticity of supply $\epsilon_{i}$ is the same at all points on the curve: \begin{equation} q_{i} = \alpha_{i} p_i^{\epsilon_{i}} \label{standard} \end{equation} Here, $\alpha_i$ is a calibrated supply parameter that captures cost factors such as wages, inputs and energy costs which remain fixed in the policy simulations. We note that the standard supply curves in PyPE can be easily modified to represent perfectly inelastic supply if the elasticity is 0 or perfectly elastic supply if the elasticity is infinity. Market equilibrium is then just the set of prices for which the demand for each product from source $i$ is equal to its supply. Focusing on the case of isoelastic supply curves, we obtain a system of non-linear equations, where each source $i\in(d,s,n)$ has the following market-clearing condition: \begin{equation} k\beta_{i}p_{i}^{-\sigma}(1+\tau_{i})^{-\sigma}P^{\sigma+\theta} = \alpha_i p_i^{\epsilon_{i}} \label{pc_eqb} \end{equation} Parameters $k$, $\alpha_{i}$, $\beta_{i}$ can be calibrated using the respective market shares of each source $i$ in the domestic market. These calibrated parameters when combined with information on the respective demand, supply and substitution elasticities are sufficient to determine the effect on prices and subsequently quantities from a change in tariffs. One practical option often observed in policy applications is to log-linearize the above system of equations, enabling a reduced form solution to be obtained for the respective price changes due to a change in tariffs. However, as noted by \citet{francois97}, linearization can often include substantial approximation error, particularly in the case of large policy shocks. Thus, we prefer to utilize a non-linear solver in PyPE when solving the above model for perfect competition. \subsection{Supply under Bertrand Competition} For supply under Bertrand competition, our sources $i\in(d,s,n)$ now represent individual firms rather than countries. Since there is no longer any need to track the number of firms per country under this framework, we drop $m_i$ from the subsequent demand equations as well. Again, the focus is only on the short run, so there is no entry or exit of firms from the domestic market. Similar to monopolistic competition, each firm incurs a fixed cost of production $f_{i}$ along with constant marginal costs $c_{i}$. The profit for each firm $i$ is then given by: \[ \pi_{i}=(p_{i}-c_{i})q_{i}-f_{i} \] Firms compete over prices with each firm $i$ choosing the price that maximizes its profits, while taking the prices of other competing firms as given. As the number of firms in the market is small, each firm's own price can also impact the aggregate price index and thus overall demand. The Nash equilibrium under these market conditions is for each firm to set their price using the following first order condition: \[ p_{i}=(p_{i}-c_{i})\left(\sigma-(\sigma+\theta)\frac{b_{i}[p_{i}(1+\tau_{i})]^{(1-\sigma)}}{\sum_{k}b_{k}[p_{k}(1+\tau_{k})]^{(1-\sigma)}}\right) \] Since information on firm's marginal costs are often unavailable, we follow \citet{Riker18} and use data on initial market shares $h_{i}$ and the elasticity parameters to calibrate the ratio of a firm's marginal costs to its prices $\frac{c_{i}}{p_{i}}$ : \[ \frac{c_{i}}{p_{i}}=\left(1-\frac{1}{\sigma-(\sigma+\theta)h_{i}}\right) \] To solve the model for a given change in tariffs, we combine the first order conditions of each firm with their respective demand equations and the CES price index. As was the case for the other supply frameworks, a non-linear solver is used by PyPE to solve this system of equations to determine the effect on prices and quantities for each firm due to a change in tariffs. \section{PyPE Implementation}\label{sec:frame} The PyPE package features a structure with three distinct layers. The innermost layer features the ``building block functions'' that codify the basic features common across all the PE models available in PyPE. The middle layer is PyPE's ``CESModel'' class, which combines the building block functions with user-supplied data in order to calibrate key parameters and organize model inputs. In addition to calibrating CES demand parameters from user-supplied inputs, the CESModel object contains functions that ensures model inputs are organized consistently, and are ready to be used by PyPE's user-facing, simulation-ready models. PyPE currently houses 3 different competition-specific, simulation-ready models. Users can choose between perfect, monopolistic, and Bertrand competition in the domestic market being analyzed.\footnote{Ongoing development of the PyPE package will include the creation of new competition-specific frameworks.} The different features of these models are described in section \ref{sec:theory}. The remainder of this section provides additional details on the layered structure of PyPE and can be useful for advanced users interested in contributing to PyPE functionality. \subsection{Building block functions}\label{sec:bbfunc} At its core, any PE model is simply a system of equations, describing the demand and supply features of a particular market or industry. By focusing on certain aspects of demand and/or supply, PE modellers aim to capture the market dynamics that are most relevant for their selected market or industry and policy experiment. PyPE facilitates this task by codifying and storing functions, such as the CES demand function, that are commonly featured in standard PE models. By having access to a set of functions that have already been validated and tested, PyPE enables practitioners to focus on adding new features to the existing PE models, rather than spend model development constructing and redefining the same set of functions that are commonly used across many different types of PE models. In its current iteration, the PyPE submodule \texttt{CES\_demand} houses the individual functions needed to solve for consumer demand in a CES framework. Given appropriate user-supplied data inputs, the \texttt{CES\_demand} functions calibrates the consumer preference parameters, the CES industry price index, and the industry-wide demand parameter. These calibrated parameters serve as key PE model inputs for calculating the effect on prices and quantity from a change in tariffs. PyPE users have direct access to these building block functions. For instance, the CES price index given in equation (3) can be accessed by a PyPE user by calling the function \texttt{PriceIndex} from the \texttt{CES\_demand} module as shown below. Here \texttt{PriceIndex} function takes a single value for the Armington elasticity of substitution and arrays of length $i$ for producer prices, tariff rates, and consumer preference weights.\footnote{In this example, we supply the CES preference weights (demand\_shifters) exogenously. In practice, preference weights will be calculated from user-supplied price and consumer expenditure data using the \texttt{CESWeights} function housed in the \texttt{CES\_demand} module.} The function returns a single value representing the CES industry price index. With access to the \texttt{PriceIndex} function, users can quickly calculate how the industry price changes in response to an increased tariff on a producer. With a few lines of code as shown below, a PyPE user can determine that the CES price index will increase by 3.8\% following the addition of a 25\% tariff on the second producer. While this example assumes perfect pass-thru of tariffs to consumers, other PyPE functions also allow for producer prices to change depending on the sort of competition employed in the market of interest as discussed in more detail in section \ref{sec:theory}. \begin{comment} \begin{lstlisting}[language = Python] #Import the CES_demand module from pype.central_functions import CES_demand #User-provided inputs armington = 3.0 #Industry elasticity of substitution demand_shifters = [.7, .2, .1] #List of preference weights p0 = [1,1,1] #List of prices, in this case normalized to 1 tf0 = [0, 0, 0] # Baseline tariff rates tf1 = [0, 0.1, 0] # New tariff rates #Compute CES Price Index P0=CES_demand.PriceIndex(elasticity = armington, weights= demand_shifters, prices = p0, tariffs=tf0) P1=CES_demand.PriceIndex(elasticity = armington, weights= demand_shifters, prices = p0, tariffs=tf1) Price_Change=(P1/P0-1)*100 \end{lstlisting} \end{comment} \newpage \begin{lstlisting}[language = Python] #Import the CES_demand module from pype.central_functions import CES_demand #User-provided inputs armington = 3.0 #Industry elasticity of substitution demand_shifters = [.7, .2, .1] #Preference weights by source p0 = [1,1,1] #List of prices, in this case normalized to 1 tf0 = [0, 0, 0] #Initial tariff rates tf1 = [0, .25, 0] #Final tariff rates with 25% tariff on producer 2 #Compute CES Price Index initial_Pindex = CES_demand.PriceIndex(elasticity = armington, weights= demand_shifters, prices = p0, tariffs=tf0) final_Pindex = CES_demand.PriceIndex(elasticity = armington, weights = demand_shifters, prices = p0, tariffs = tf1) print((final_Pindex/initial_Pindex)-1) #Change in CES price index of 3.8% \end{lstlisting} A key feature of PyPE's building block functions is that they are formulated to be agnostic to the number of sources/producers within a market. As such, PyPE functions and competition-specific models can be executed to solve the PE models with any number of user-specified firms/sellers participating in the domestic market. In doing so, users have significantly more flexibility in their policy applications than existing tools that often require the number of firms/sellers to be pre-defined and hard coded. The PyPE building block functions represent the most basic modeling features and tools for organizing data inputs and outputs. End users that are interested in using PyPE for running model simulations from completed models will rarely interact with building block functions directly but should know that those building block functions are being used in the background by the other levels of the PyPE framework. These functions can also be helpful for developing new model features and tools for performing PE analysis, and future development of PyPE will focus on expanding the universe of building block functions to help model new forms of demand, competition, and interactions between different markets and industries. \subsection {Organizing inputs and calibration using a CESModel object }\label{sec:module} As an object-oriented programming language, Python allows data and functions which act upon that data to be grouped together and accessed as objects of a specific class. PyPE utilizes this feature of Python and organizes the building block functions with user-supplied input data as a specialized class object called CESModel. The CESModel object ensures that input data and simulation results are consistently structured, regardless of the specific PE model or equilibrium conditions being used. All user-supplied and calibrated parameters are stored in the same location, and can be accessed using the same methods regardless of which competition-specific PE model is being used. Doing so helps ensure a consistent logic for developing new PE models and adding new features to existing models. At the same time, the CESModel object ensures users can easily run simulations using the same input data with different types of competition models and thus test the sensitivity of their results to different assumptions on market structure. The competition-specific PE models housed in the PyPE package requires user to provide certain data inputs and parameter values. Due to the CES demand structure, a number of these inputs are the same irrespective of the competition-specific PE model being used for simulations.\footnote{ Future iterations of PyPE feature additional objects for other, non-CES demand structures such as linear demand. New demand structures will likely require different data requirements and take on different calibration steps.} To successfully initialize the CESModel object in PyPE, users need to provide the following data inputs at minimum: \begin{enumerate} \item Value of domestic shipments and imports from each source (country, firm, plant, etc.).\footnote{Users can optionally supply information on firm/product prices, although all prices are normalized to 1 as a default behavior. In our experience, doing so improves the ability of Scipy's Fsolve function to solve for prices in the new equilibrium, while still allowing for results to be reported in terms of percentage changes.} \item Initial and new tariff rates for the different sources supplying the domestic market \item Information on the relevant elasticities in the market. All PE models in PyPE require users to provide the elasticity of substitution. Users also have the option to provide the industry demand elasticity, which is otherwise assumed to be -1 to match a Cobb-Douglas structure of demand across different product groups. Lastly, for perfect competition PE models, users also need to enter the elasticity of supply by source. \end{enumerate} Once initialized, the CESModel object stores the substitution and industry demand elasticities as attributes. The user-supplied matrix of market shares of each source of supply is also added to the CESModel object. Using PyPE's building block CES functions and user-supplied inputs, the CESModel calibrates and stores an initial industry price index, $P$, and CES preference parameters, $b_{i}$. CESModel objects also store the functions for solving for CES demand which are used to solve for new equilibrium conditions during PE model simulations. In practice, most users will rarely interact with CESModel objects directly and will instead run model simulations using PyPE's user-facing functions that draw heavily from the CESModel class. However, PyPE users interested in developing new CES models can benefit from having access to the CESModel class as a starting point. \subsection {Off-the-shelf competition-specific models for PE simulations }\label{sec:models} By combining user-provided data with built-in CES functions, the CESModel object has almost everything needed to solve a PE model. The last remaining requirement is for the user to select how sources of supply compete with one another when supplying the domestic market. In its current version, PyPE offers users three finalized, competition-specific models: perfect competition, monopolistic competition, and Bertrand competition. These models combine user-supplied inputs, calibrated CES parameters, and the competition-specific equilibrium condition to execute PE simulations. Results from the simulations are organized and stored in the model object and output to an excel spreadsheet format. The type of market competition chosen by the user determines the market-clearing equilibrium conditions for conducting the policy simulation in PyPE. Thus, users should ensure that the selected market competition matches the key characteristics of the industry being analyzed. PyPE users interested in running PE simulations, rather than developing new models can use these competition-specific models to easily execute a simulation with little coding or programming required. Model users supply data inputs while the off-the-shelf PyPE model performs the actual task of calibrating demand parameters, solving for new equilibrium conditions, and reporting simulation results. Section 4 provides some simple examples of how users can execute a PE simulation using PyPE's different competition-specific models. \begin{comment} \begin{lstlisting}[language = Python] #Import the bertand_model class from PyPE's imperfect_competition.betrand_model module from pype.imperfect_competition.bertrand_model import Bertrand #Import pandas and construct producer-level data inputs to be used in simulation import pandas as pd prices=[1,1,1] t0=[0,0.0,0]; t1=[0,0.0,0.25] expenditures=[70,10,20] firm_data = pd.DataFrame({"producer":["Weyland", "Tyrell","CHOAM"], "prices0":prices, "expenditures0":expenditures, "tariffs0":t0, "tariffs1":t1}) #Execute a Bertrand model simulation, storing inputs and results in a variable called 'bertrand_object' #User supplies the firm level data via the "parameter matrix" argument as well as industry, Armington elasticities #Simulation results are saved in an excel file at the path specified in the 'output_path' argument bertrand_object = Bertrand(parameter_matrix = firm_data, armington = 3.0, industry_elasticity = -1, output_path = "G:/data/chris_montgomery/PyPE_demo/bertrand_demo.xlsx") \end{lstlisting} \end{comment} \subsubsection {Additional User Features for Modeling Perfect Competition}\label{sec:models:PCoptions} PyPE users analyzing markets operating under perfect competition have the option to also select the functional form of the supply curve in order to better capture certain seller characteristics. Currently, the options are isoelastic, perfectly elastic, perfectly elastic, and asymptotic. These can be chosen separately for each producer (country). Each of these forms requires one parameter chosen by the user and one calibrated parameter (for some forms, the user chosen parameter is unused). The `standard' supply form is isoelastic, so the price elasticity of supply is the same at all points on the curve. The elasticity $\epsilon_{i}$ is supplied by the user while the scalar $\alpha_{i}$ is calibrated from the data. The perfectly elastic and perfectly inelastic supply forms are extreme variants of the `standard' supply form. Both of these functions only use a calibrated parameter $\alpha_{i}$, but that parameter is interpreted differently. With perfectly inelastic supply, quantities do not respond at all to prices. For this form, the calibrated parameter is the quantity produced for all prices. This is the same result as using the `standard' isoelastic form and setting the constant elasticity to zero. With perfectly elastic supply, any quantity can be produced as long as price is greater than or equal to the constant marginal cost. For this form, the calibrated parameter is the constant marginal cost. While any quantity supplied is possible when price is greater than or equal to the marginal cost of this form, the equation is defined in equilibrium so that the quantity supplied in that case is equal to quantity demanded. \section{PyPE demonstration}\label{sec:demo} In this section we demonstrate how to use PyPE. We begin with a simple example featuring three sources of production: domestic, non-subject, and subject. Each producer faces zero tariffs in the initial equilibrium. Following a policy change, the subject source of supply faces a tariff. As such, simulation results represent the effect of the new tariff on market outcomes. In order to demonstrate PyPE flexibility, we run simulations for each available competition framework in PyPE and conclude the section by discussing how choice of supply framework influences model outcomes in this simple example. All the PyPE simulations follow these simple steps. First, the user enters producer-level data and tariffs using Python's Pandas package as demonstrated in the below code: \begin{lstlisting}[language = Python] #User-provided producer-level data inputs import pandas as pd #Import the Pandas package initial_prices=[1,1,1] producer_expenditures=[70,10,20] initial_tariffs=[0,0,0] final_tariffs=[0,0,0.25] producer_data=pd.DataFrame({ "producer":["Domestic","Non-Subject","Subject"], "prices0":initial_prices, "expenditures0":producer_expenditures, "tariffs0":initial_tariffs, "tariffs1":final_tariffs }) \end{lstlisting} Table \ref{tab:sim_params} summarizes the selected model data used to generate the PE simulation results featured in this section. \begin{table}[h] \caption {Selected parameters for PyPE demonstrations} \label{tab:sim_params} \centering \resizebox{.66\textwidth}{!}{% \begin{tabular}{|l|l|} \hline Parameter & Values \\ \hline Sources/Producers & Domestic, Non-subject, Subject \\ \hline Source market shares & 70, 10, 20 \\ \hline Source initial tariffs & 0, 0, 0 \\ \hline Source final tariffs & 0, 0, 0.25 \\ \hline \end{tabular}% } \end{table} The next step is for the user to select the model class from PyPE's competition modules that best fits their market characteristics. Users then initiate their competition-specific model object with the user-provided producer-level dataframe, an industry-wide price elasticity of demand, and the elasticity of substitution. To ensure consistency across models, an elasticity of substitution of 3 and an industry demand elasticity of -1 are used as the elasticity parameters in all these simulations. Upon initialization, PyPE runs the desired simulation, stores inputs and results within the model object, and constructs an excel results spreadsheet at the user-specified output path. The next sections will show how users can execute the three different competition frameworks in PyPE. \subsection{Model simulation: Monopolistic competition} To use the data given in Table \ref{tab:sim_params} with a PE model of monopolistic competition, we can run the following code. The first line imports the requisite Monopolistic model object, while the second line constructs a model object with the user supplying producer data, elasticity values, and an output file path: \begin{lstlisting}[language = Python] #Import the Monopolistic Competition model from PyPE from pype.monopolistic_competition.moncomp_model import Monopolistic moncomp_model=Monopolistic(parameter_matrix = producer_data, elasticity = 3.0, industry_elasticity = -1, output_path ="DesiredFilePath.xlsx") \end{lstlisting} Table \ref{tab:monopolostic} summarizes firm-level outcomes from the monopolistic competition scenario. Firms do not change their prices in response to the tariff, consistent with the constant markup assumption underlying monopolistic competition. Thus, consumers will face a full pass through of the 25 percent increase in tariff, resulting in a 25 percent increase in prices paid for products from the subject producer. All other prices remain the same with the higher tariff leading to changes in the amount of good sold from each producer in the market. As expected, total expenditures and quantities consumed from the subject producer drop significantly by 31 percent and 44 percent respectively in response to domestic consumers facing higher prices for their product after the full pass through of the 25 percent tariff. Conversely, domestic and non-subject firms benefit from the tariff on subject firms, experiencing a symmetrical increase of 7.75 percent in quantities and expenditures following the imposition of the tariff. \begin{table}[h] \caption {Results from simulations of Monopolisitc Competition model} \label{tab:monopolostic} \resizebox{1\textwidth}{!}{% \begin{tabular}{|l|l|l|l|l|l|l|l|} \hline \multicolumn{1}{|c|}{\textbf{Source}} & \multicolumn{1}{c|}{\textbf{expenditures0}} & \multicolumn{1}{c|}{\textbf{expenditures1}} & \multicolumn{1}{c|}{\textbf{quantities0}} & \multicolumn{1}{c|}{\textbf{quantities1}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}expenditures \\ \% change\end{tabular}}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}prices \\ \% change\end{tabular}}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}quantities \\ \% change\end{tabular}}} \\ \hline Domestic & 70.00 & 75.43 & 70.00 & 75.43 & 7.76 & 0.00 & 7.76 \\ \hline Non-subject & 10.00 & 10.78 & 10.00 & 10.78 & 7.76 & 0.00 & 7.76 \\ \hline Subject & 20.00 & 13.79 & 20.00 & 11.03 & -31.03 & 0.00 & -44.83 \\ \hline \end{tabular}% } \end{table} \subsection{Model simulation: Perfect Competition} In addition to the selected model parameters featured in table \ref{tab:sim_params}, the perfect competition model in PyPE requires users to supply a source-specific ``form-supply" and ``paramB" supply elasticity parameter. For this demonstration, we select the "standard" form for the supply curves and a value of 2.0 for the supply elasticity for each of the three sources of supply. The code to run the simulation under Perfect Competition is given below with the simulation results reported in table \ref{tab:perf_comp} \begin{lstlisting}[language = Python] #Import the Perfect Competition model from PyPE from pype.perfect_competition.perfcompetition_model import PerfComp producer_data["paramB"]=[2,2,2] #Supply elasticities producer_data['form_supply']='standard' #Supply fuctional form pc_model=PerfComp(parameter_matrix = producer_data, elasticity = 3.0, industry_elasticity = -1, output_path ="DesiredFilePath.xlsx") \end{lstlisting} \begin{table}[h] \caption {Results from simulations of perfect competition model} \label{tab:perf_comp} \resizebox{1\textwidth}{!}{% \begin{tabular}{|l|l|l|l|l|l|l|l|} \hline \multicolumn{1}{|c|}{\textbf{Source}} & \multicolumn{1}{c|}{\textbf{expenditures0}} & \multicolumn{1}{c|}{\textbf{expenditures1}} & \multicolumn{1}{c|}{\textbf{quantities0}} & \multicolumn{1}{c|}{\textbf{quantities1}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}expenditures\\ \% change\end{tabular}}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}prices \\ \% change\end{tabular}}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}quantities \\ \% change\end{tabular}}} \\ \hline Domestic & 70.00 & 72.37 & 70.00 & 71.57 & 3.38 & 1.11 & 2.24 \\ \hline Non-subject & 10.00 & 10.34 & 10.00 & 10.22 & 3.38 & 1.11 & 2.24 \\ \hline Subject & 20.00 & 17.30 & 20.00 & 15.64 & -13.52 & -11.56 & -21.78 \\ \hline \end{tabular} } \end{table} \noindent Again, model simulation results show a reduction in market shares and price declines for the source subjected to the new tariff. Since we have assumed an upward-sloping supply curve, the subject producer reduces its price by 11.6 percent after the tariff is imposed, slightly counteracting the 25 percent ad valorem tariff. Still, consumers purchase 21.8 percent lower quantities from the subject producer. As expected, the domestic and non-subject producer benefit from the imposition of the tariff. Both domestic and non-subject producers are able to raise their prices by 1.10 percent while consumers increase the quantities purchased from both non-subject sources by 2.24 percent. \subsection{Model simulation: Bertrand} The following code runs a PE simulation under a Bertrand competition for data given in Table \ref{tab:bertrand}: \begin{lstlisting}[language = Python] #Import the Bertrand Competition model from PyPE from pype.imperfect_competition.bertrand_model import Bertrand bertrand_model=Bertrand(parameter_matrix = producer_data, elasticity = 3.0, industry_elasticity = -1, output_path ="DesiredFilePath.xlsx") \end{lstlisting} Table \ref{tab:bertrand} contains results from the PyPE simulation of a market characterized by Bertrand imperfect competition. The results table features an additional \texttt{Marginal Costs} column, which is each producers' marginal costs calibrated using initial market conditions. Intuitively, the firm with the largest market share, A, features the lowest marginal costs. More generally, we see that calibrated marginal costs are inversely related to producers' initial market share. The 25 percent tariff change leads to large changes in the market characterized by Bertrand competition. Each producer experiences significant changes in consumer expenditures with the subject firm seeing a drop in revenues of nearly 22 percent, due to both a reduction in prices and quantities. The subject producer reduces its prices, however by a substantially smaller level than the magnitude required to fully cover the 25 percent tariff. As such, consumer prices for the subject product increases. Consumer expenditures on domestic producer increased nearly 4 percent with the domestic producer able to increase it's prices by 6 percent. There is a larger effect on consumer expenditures on the non-subject firm mostly due to an increase in quantities sold. These pricing strategies represent a notable contrast to the relatively uniform changes in consumer prices across each firm in the monopolistic and perfect competition scenario. \begin{table}[h] \caption {Results from simulations of Bertrand Competition model} \label{tab:bertrand} \resizebox{1\textwidth}{!}{% \begin{tabular}{|l|l|l|l|l|l|l|l|l|} \hline \multicolumn{1}{|c|}{\textbf{Source}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}Marginal\\ Costs\end{tabular}}} & \multicolumn{1}{c|}{\textbf{expenditures0}} & \multicolumn{1}{c|}{\textbf{expenditures1}} & \multicolumn{1}{c|}{\textbf{quantities0}} & \multicolumn{1}{c|}{\textbf{quantities1}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}expenditures \\ \% change\end{tabular}}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}prices \\ \% change\end{tabular}}} & \multicolumn{1}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}quantities \\ \% change\end{tabular}}} \\ \hline Domestic & 0.38 & 70.00 & 72.75 & 70.00 & 68.43 & 3.93 & 6.31 & -2.24 \\ \hline Non-subject & 0.64 & 10.00 & 11.60 & 10.00 & 11.52 & 15.97 & 0.65 & 15.23 \\ \hline Subject & 0.62 & 20.00 & 15.65 & 20.00 & 12.77 & -21.75 & -1.98 & -36.13 \\ \hline \end{tabular}% } \end{table} \subsection{Summarizing competition-specific models} Figure \ref{fig:indices} depicts the change in the CES industry price indices across the different modeling scenarios. Intuitively, we see that industry-wide prices are most affected in the Bertrand simulation, and most muted in the perfect competition model. The change in the industry price observed in the monopolistic competition scenario nearly represents a midpoint between perfect competition and Bertrand scenarios. \begin{figure}[h!] \caption{Changes in CES price indices across simulated model scenarios} \includegraphics[width=.75\textwidth]{PriceIndices.png} % alt text: This is a bar chart showing the percentage change in industry price index across the perfect competition, monopolistic competition, and Bertrand models. The Perfect Competition model has the small increase while the Bertrand model has the largest. \centering \label{fig:indices} \end{figure} A more robust discussion of trade-offs and appropriate applications of the various competition-specific models currently housed in the PyPe framework is beyond the scope of this introductory paper. However, figure \ref{fig:comparison} provides comparisons of simulated changes in industry price indices and major producer-specific outcomes across the different competition-specific modeling scenarios. As the figure shows, the choice of type of competition to be applied to a modeling scenario does have notable implications for how firms adjust prices and consumers respond in the wake of a change in tariff policy. From the figure, the negative effects on quantity and expenditure for the subject producer are larger in the monopolistic competition simulation compared to perfect and Bertrand competition scenarios. PyPE thus can be a helpful tool for understanding how these different types of competition can influence simulated outcomes. In the future, PyPE developers plan to augment the package with new tools to allow model users to seamlessly produce visualizations and other analyses for performing this type of sensitivity analysis and compare outcomes across a variety of simulations. Ultimately, we believe the ease of which users can access and compare different model simulations within a single PyPE framework can help end users generate interesting new insights into the implications of modeling assumptions for specific research questions. \begin{figure}[h!] \caption{Changes in producer-level outcomes across simulated model scenarios} \includegraphics[width=\textwidth]{simulations_facet.png} % alt text: This is a figure with 9 bar charts (3 rows, 3 columns) showing simulated changes in firm level outcomes. The columns are based on firm type (Domestic, Non-Subject, and Subject) and the rows are based on outcome of interest (Prices, Quantities, and Expenditures). Within each bar chart, there are individual bars for the monopolistic competition, perfect competition, and Bertrand models to show how the outcomes differ between models. \centering \label{fig:comparison} \end{figure} \section{Future Modifications}\label{sec:conclude} Regarding future development, PyPE will focus on two distinct areas. For end users and individuals with less programming and modeling experience, developers will continue to work on expanding the suite of ``off-the-shelf" models and model features so that PyPE has more ability to analyze different markets and sectors. In the immediate future, PyPE developers will focus on enabling: \begin{itemize} \item a Nested-CES Option with user-defined nest assignment, \item non-CES demand structures such as linear demand, \item new competition modules such as Cournot competition, and \item additional user features such as sensitivity analysis and results visualizations \end{itemize} As PyPE is an open source project, it stands to benefit from contributions and collaborations with the larger PE modeling community. To that end, PyPE developers will continuously encourage modelers to use the package to ``Pythonize" existing PE models or create new ones. In doing so, contributors will be adding their work to an ever-growing repository of models while helping develop new tools and frameworks for future model building efforts and policy applications. \newpage \bibliographystyle{chicago} \bibliography{references} \end{document} @techreport{Riker14, author = {Riker, David}, title = {Estimates of the Impact of Restrictions on Cross-Border Trade in Services}, institution = {United States International Trade Commission}, year = {2014}, type = {USITC Office of Economics Research Note}, number = {RN-2014-01A}, address = {Washington, DC}, } @techreport{USITC2019, title = "U.S.-Mexico-Canada Trade Agreement: Likely Impact on the U.S. Economy and on Specific Industry Sectors", author = "USITC", institution = "United States International Trade Commission", year = "2019", type = "Investigation Number: TPA 105-003", number = "publication 4889", address = "Washington, DC" } @techreport{USITC2021a, title = "Caribbean Basin Economic Recovery Act: Impact on U.S. Industries and Consumers and on Beneficiary Countries", author = "USITC", institution = "United States International Trade Commission", year = "2021", type = "Investigation Number: 332-227", number = "publication 5231", address = "Washington, DC" } @techreport{USITC2021b, title = "Raspberries for Processing: Conditions of Competition between U.S. and Foreign Suppliers, with a Focus on Washington State", author = "USITC", institution = "United States International Trade Commission", year = "2021", type = "Investigation Number: 332-577", number = "publication 5194", address = "Washington, DC" } @techreport{Riker18, author = {Riker, David}, title = {MODELING THE FINANCIAL IMPACT OF TARIFFS IN CONCENTRATED PRODUCT MARKETS}, institution = {United States International Trade Commission}, year = {2018}, type = {USITC Office of Economics Research Note}, number = {RN-2018-10B}, address = {Washington, DC}, } @article{Krugman1979, title={Increasing returns, monopolistic competition, and international trade}, author={Krugman, Paul R}, journal={Journal of international Economics}, volume={9}, number={4}, pages={469--479}, year={1979}, publisher={Elsevier} } @techreport{Ahmad19, author = {Ahmad, Saad}, title = {Conducting Profitability Analysis in Partial Equilibrium Models with Monopolistic Competition}, institution = {United States International Trade Commission}, year = {2019}, type = {USITC Office of Economics Research Note}, number = {RN-2019-07B}, address = {Washington, DC}, } @article{francois97, title={Partial equilibrium modeling}, author={Francois, Joseph F and Hall, H Keith}, journal={Applied methods for trade policy analysis: A handbook}, pages={122--155}, year={1997}, publisher={Cambridge University Press Cambridge} } @article{armington1969, title={A theory of demand for products distinguished by place of production}, author={Armington, Paul S}, journal={Staff Papers}, volume={16}, number={1}, pages={159--178}, year={1969}, publisher={Springer} }