[PYTHON] Farmer economy simulation ① (net-seller, self-sufficient farmer, net-buyer utility maximization action) _Explanation

Hello. I am a graduate student studying agricultural economics.

Suddenly, among those who are studying economics and are also interested in programming, Has anyone used CGE (computable general equilibrium) or SAM (Social Accounting Matrix), which are used in policy evaluation, in their research? Although I longed for such a simulation method, I couldn't use it in my research for various reasons ** Note 1 ** </ sup>.

However, I really wanted to try it myself, so I thought that I wouldn't have to use it for research anymore, so I decided to make agricultural economic simulation software as a hobby. Also, it's boring to just make it normally, so I hope it will eventually be shaped like a game and sold as an indie game on STEAM. At worst, it would be interesting if you could make a video on youtube or niconico (like a biim system, etc.).

After a lot of trial and error under the above motivation, I was able to simulate the utility maximization of the farmer, which is the model of the farmer economy simulation game, so I will keep a record while sandwiching the explanation of the model appropriately.

Environmental information

This article python 3.8.3 scipy 1.5.0 Is used on jupyter notebook. (Is this the way to write ...?)

Explanation of the assumed farmer economic model

Below, I explained how to solve the utility maximization problem, which is the core of the simulation, and how to set the farmer's behavior. I think it's okay to fly to the next article for those who are sloppy or who are not interested in setting agricultural economic models. I will give a minimum explanation in the next time.

Explanation of the model using words

What kind of crops do farmers make?

The farmer of this model produces only grain A, which is the staple food of the assumed area. They then eat, sell and buy a certain amount of grain A to satisfy their appetite.

The assumed area is rural Mexico, and the image of grain A is corn for feed.

In the process of maximizing utility, farmers are divided into "mainly selling farmers", "self-sufficient farmers" and "mainly buying farmers".

In the process of maximizing their utility, the farmers in this model allocate farmland and labor to the three means of earning income: grain A production, non-farm labor, and farm land lease. However, in the state of maximizing utility, depending on the conditions set by the farmer, "Sell the surplus after self-sufficiency of grain A", "Make grain A only for yourself", "Self-sufficiency of grain A is sufficient" There are various things such as "buy what you don't have from others".

Therefore, based on Janvry (1991), the above three patterns net-seller = "Sell the surplus after self-sufficiency of grain A" Self-sufficient farmer = "Make grain A just for yourself" net-buyer = "Self-sufficient grain A and buy the shortage from others"

Divided into.

As is clear from the above classification, although the above three patterns of farmers are "farmers", only net-sellers can earn agricultural income.

What do farmers consume as consumers?

In this model, a "utility function" is assumed as the objective function of optimization. Utility is obtained by consuming "leisure" and "other goods". Strictly speaking, "leisure" is obtained by allocating time owned by oneself, and "other goods" is obtained by purchasing.

The consumption of grain A was excluded from the utility function, and a constraint was created assuming that a certain amount must be consumed (named the satiety constraint).

How do I get non-agricultural income?

Net-sellers have no choice but to make and sell grain A on their farmland, Net-buyer and self-sufficient farmers can earn income from off-farm labor and farmland leasing.

I also included transaction costs

In this model, net-seller and net-buyer impose transaction costs when buying and selling grain A ** Note 2 ** </ sup>. For net-seller, when selling grain A, (price-transaction cost) becomes the price, For net-buyer, the price is (price + transaction cost) when you buy grain A.

Similarly, net-sellers, self-sufficient farmers, and net-buyer charged transaction costs in the same way as above when buying and selling labor.

See Janvry (1991) for why I put this in. Roughly speaking, it costs money to find a market to buy and sell, and to carry grain A. Originally, if the market is functioning properly, theoretically all farmers should be "net-seller" or "net-buyer". A "self-sufficient farmer" is born under the conditions in which such transaction costs are incurred.

How did you find the optimal solution?

The optimal solution is not "calculated". I used the minimize function of scipy.optimize to find a solution like that with the SLSQP method.

I'm sure there are people who thought, "Hey, that's not right," so let me make an excuse.

Actually, I originally thought of a farmer model that produces multiple crops by setting a Cobb-Douglas type function for the utility function and the production function. At first, I wanted to find the optimal solution by hand calculation and copy the result to the code, but it was troublesome + it seemed impossible depending on the model type, so I decided to find the solution with the minimize function. The SLSPQ method was used as the method for finding the optimal solution because both the objective function and the constraint are non-linear. However, I couldn't find the optimal solution, so I stopped Cobb-Douglas and continued to use a simpler functional type.

Then, I pasted the formula of the optimization problem below.

Utility maximization problem formula

net-seller Max

U = a_oC_o+a_ll+{1/2}*(a_{o,o}C_o^2+a_{l,l}l^2+a_{o,l}*C_o*l)...(1)

s.t.

(p_a-t_a)*(Yield*Equip*La-appe)>(w+t_w)Ln+r*An+p_oC_o+MilkMeat...(2:Liquidity constraints) \\ Yield*Equip*La>appe...(3:Satiety constraint) \\ (Aa+An)/(La+Ln)=Equip...(4:Land equipment rate constraints) \\ L>La+l...(5:Labor endowment constraints) \\ A>Aa...(6:Farmland endowment constraints) \\All variables>0

$ U $: Utility (satisfaction) $ a_o, a_l, a_ {o, o}, a_ {ll}, a_ {o, l} $: Parameters of the quadratic model ** Note 3 ** </ sup>. $ C_o $: Consumption of other goods (image is Netflix or billing smartphone game) $ L, La, l $: Owned labor (24-6 = 18 hours), labor used for grain A production, leisure $ A, Aa $: Owned farmland area (2ha), farmland used for grain A production $ Ln, An $: Hired labor, rented farmland $ w, r, t_W, p_a, t_a, p_o $: Wage (hourly wage), rent (1 season), transaction cost when participating in non-farm labor (per transaction volume), price of grain A, purchase of grain A Occasional transaction costs and prices of other goods $ appe, MilkMeat, Yield, Equip $: appetite (constant, consumption of grain A in one season), milk and meat consumption (constant, one season), yield (constant, kg / ha), land equipment rate (Constant, ha / hour)

Self-sufficient farmer

max

U = a_oC_o+a_ll+{1/2}*(a_{o,o}C_o^2+a_{l,l}l^2+a_{o,l}*C_o*l)...(1)

s.t.

(w-t_w)Ln+rAn>p_oC_o+MilkMeat...(2:Liquidity constraints) \\ Yield*Equip*La>appe...(3:Satiety constraint) \\ Aa/La=Equip...(4:Land equipment rate constraints) \\ L>La+Ln+l...(5:Labor endowment constraints) \\ A>Aa+An...(6:Farmland endowment constraints) \\All variables>0

$ U $: Utility (satisfaction) $ a_o, a_l, a_ {o, o}, a_ {ll}, a_ {o, l} $: Parameters of the quadratic model ** Note 3 ** </ sup>. $ C_o $: Consumption of other goods (image is Netflix or billing smartphone game) $ L, La, Ln, l $: Owned labor (24-6 = 18 hours), labor used for grain A production, non-agricultural labor, leisure $ A, Aa, An $: Owned farmland area (2ha), farmland used for grain A production, rented farmland $ w, r, t_W, p_o $: Wages (hourly wages), rents (1 season), transaction costs when participating in non-farm labor (per transaction volume), prices of other goods $ appe, MilkMeat, Yield, Equip $: appetite (constant, consumption of grain A in one season), milk and meat consumption (constant, one season), yield (constant, kg / ha), land equipment rate (Constant, ha / hour)

net-buyer max

U = a_oC_o+a_ll+{1/2}*(a_{o,o}C_o^2+a_{l,l}l^2+a_{o,l}*C_o*l)...(1)

s.t.

(w-t_w)Ln+rAn>(p_a+t_a)C_a+p_oC_o+MilkMeat...(2:Liquidity constraints) \\ Yield*Equip*La+C_a>appe...(3:Satiety constraint) \\ Aa/La=Equip...(4:Land equipment rate constraints) \\ L>La+Ln+l...(5:Labor endowment constraints) \\ A>Aa+An...(6:Farmland endowment constraints) \\All variables>0

$ U $: Utility (satisfaction) $ a_o, a_l, a_ {o, o}, a_ {ll}, a_ {o, l} $: Parameters of the quadratic model ** Note 3 ** </ sup>. $ C_a, C_o $: Purchase amount of grain A, consumption amount of other goods (image is Netflix and billing smartphone game) $ L, La, Ln, l $: Owned labor (24-6 = 18 hours), labor used for grain A production, non-agricultural labor, leisure $ A, Aa, An $: Owned farmland area (2ha), farmland used for grain A production, rented farmland $ w, r, t_W, p_a, t_a, p_o $: Wage (hourly wage), rent (1 season), transaction cost when participating in non-farm labor (per transaction volume), price of grain A, purchase of grain A Occasional transaction costs and prices of other goods $ appe, MilkMeat, Yield, Equip $: appetite (constant, consumption of grain A in one season), milk and meat consumption (constant, one season), yield (constant, kg / ha), land equipment rate (Constant, ha / hour)

About utility function

A quadratic model was used with reference to Note 3. The coefficient multiplied by l and Co is the utility obtained when each good is consumed. The coefficient multiplied by l × Co is the utility obtained when two are consumed at the same time (what is the name?). The reason why there is a benefit when consuming two at the same time is that there is no happy person if you only have leisure time, and there is no happy person if you only have Netflix or smartphone game, and you have to have time to play and something to play at the same time. ..

Production function

Probably the biggest problem is the production function. In general, economics assumes a diminishing marginal effect for each input factor. Therefore, functional types that can express that assumption are often used.

So I thought the Cobb-Douglas type was probably the safest, but as mentioned above, I couldn't find the optimal solution in that case. The Cobb-Douglas type is a concave function, so there should be no problem, but probably a lot of constrained expressions are bad.

So, as a result of worrying for two months, I ended up with the above feeling. But I really wanted to use the Cobb-Douglas type ...

How did you decide the value used as the parameter?

Each parameter used for utility maximization was extracted from actual data and reference materials. Below is the explanation.

Utility function coefficient

If you really do the coefficient of the utility function, you probably have to do structural type inference (I have never done it). We used the consumption share of the household consumption survey results in Mexico. The utility when consuming two goods at the same time is appropriately set.

Actually, assuming Cobb-Douglas utility function + constant yield, this method is theoretically fine, but this time we used a quadratic model, so it should not be exactly the correct method. If it is a quadratic model, can the parameters be calculated from the consumption amount share? I don't know because the theory is difficult.

Specifically, the coefficient of the utility function was calculated as follows. 2018 Household Consumption Survey Results (ENIGH) ** Note 4 ** </ sup> "trabajos_2018.csv", "poblacion_2018.csv", "concentradohogar_2018.csv" published by the National Institute of Statistics and Geography of Mexico (INEGI) I used. The calculated values are (1) average wages of non-self-employed people in the countryside, (2) consumption share calculated using leisure as opportunity cost, and (3) consumption share of goods that are not daily necessities.

Equip (land equipment rate), how many days is one season?

Since we could not find Mexican data on Equip (land equipment ratio), we used the data of feed corn in Japan ** Note 5 ** </ sup>.

〇 Land equipment rate (p24) Working hours per 10a in prefectures required for the entire process of feed corn production Sowing-related: 1.2 hours, topdressing herbicide: 0.8 hours, harvest: 1.6 hours, cutting and stuffing: 1.6 hours → 5.2 hours / 10a = 52 hours / ha → Land equipment rate: 1/52 (ha / hour)

〇 How many days do you assume for one season? (P32) Here, varieties with a relative maturity of 110-120 days are assumed, so → Cultivation days: 4 months = 120 days

Rent (Mexico peso), endowed labor per season

I searched for the rent but couldn't find it, so I referred to the results of a personal interview in Mexico. The farmer interviewed rented a 0.1ha green house for 2000peso. → It is assumed that 1ha of farmland can be rented for 2000peso.

Assuming that one season = four months of renting farmland Rent per 4 months: 2000 * 4 = 8000peso Also, Endowed labor per 4 months: (24-6) * 30 * 4

Price of Yield (yield), grain A (corn for feed)

** Note 6 ** </ sup> with reference to public data from the Mexican Agriculture, Livestock and Fisheries Information Authority (SIAP).

〇 For one year in 2018, rainwater agriculture (temporal), nationwide Planted area: 396397.92 ha, yield: 8324248200 kg, production value: 5024207380 peso → Price: 5024207380/8324248200 = 0.6036 (peso / kg) → Unit yield: 5024207380 / 396397.92 = 12675 (kg / ha) The production value per unit area per month: 1912 (peso / ha), the production value per unit area per day: 64 (peso / ha)

Transaction costs, food costs, and per capita consumption of corn for non-agricultural income

I didn't know this either, so I used the results of my personal interview in Mexico.

〇 General household food expenses for one day (father, mother, two sons = four people's food expenses) Meat: 130 peso / kg → 130/4 peso / 0.25kg / person Tortilla: 15 peso / kg → 15/4 peso / 0.25kg / person Milk: 25 peso / L → 25/4 peso / 0.25L / person

Since it is troublesome, it is assumed that 1 kg of tortilla = 1 kg of maize. → Daily consumption of meat (0.25kg) and milk (0.25L): 130/4 + 25/4 (peso / person) → Daily consumption of tortillas: 15/4 → One person eats 0.25 kg of tortillas a day. Assuming

As a result of the same interview, he said that the transportation cost to work is about 20 peso. Therefore, the transaction cost for external labor is 20 peso. → As I noticed now, in this model, 20peso was set as the cost per input labor, but this should be the fixed transaction cost. Is that okay?

Prices of other consumer goods

It seems that the average household consumption per day is about 200peso, so Appropriately, let's assume that one other consumer good is consumed per day, and set it to 30 peso.

at the end

That's all for setting the conditions. Next time, I'll show you the code, but I'll decline only two points.

First of all, this simulation is not complete. Since we are aiming for a farmer economy "game" in which many farmers cooperate / compete, we plan to bring it to the form of multi-agent simulation at the end. So the code is organized in a multi-agent extensible way. Please note that it may be difficult to see as a mere simulation.

Next, in this simulation, we use scipy.optimize in Python to forcibly find such a solution without calculating the optimal solution. So, I don't think it's true, but be careful if you use this code to create material that requires rigorous discussion. This may not be the global optimal solution. Also, the functional type of the production function and the parameter estimation of the utility function are probably bad ways.

Finally, if there are "people who are familiar with economic models" or "people who are familiar with solving optimization problems using programming languages", I would appreciate any advice on how to make a good simulation model.

See you again next time.

Annotation

** Note 1 ** </ sup> (1) The price of frequently used software (GAMS, etc.) is high, (2) It is difficult to find the significance of research, and (3) Learn how to use dedicated software. Is troublesome.

** Note 2 ** </ sup> In the future, I would like to make this transaction cost different depending on the conditions of the farmer. For example, farmers who are far from the market will have higher transportation costs and transaction costs due to the distance.

** Note 3 ** </ sup> Yukinobu Kitamura "1999 Comparative Statistical System Theory, Lecture Materials (?)" Http://www.ier.hit-u.ac.jp/~kitamura/lecture /Hit/99Statsys4_c.pdf

** Note 4 ** </ sup> https://www.inegi.org.mx/programas/enigh/nc/2018/

** Note 5 ** </ sup> Tsutomu Kanno "Current status of corn cultivation for feed and technological development for future planting expansion" https://www.maff.go.jp/kanto/seisan/ tikusan / kihon_zyoho / pdf / corn_gizyutu.pdf

** Note 6 ** </ sup> https://www.gob.mx/siap

Recommended Posts

Farmer economy simulation ① (net-seller, self-sufficient farmer, net-buyer utility maximization action) _Explanation
Farmer economy simulation ② (net-seller, self-sufficient farmer, net-buyer utility maximization action) _