@@ -165,10 +165,11 @@ def preprocess_puf(puf: pd.DataFrame) -> pd.DataFrame:
165165 puf ["qualified_tuition_expenses" ] = puf .E03230
166166 puf ["real_estate_taxes" ] = puf .E18500
167167 puf ["rental_income" ] = puf .E25850 - puf .E25860 # Schedule E rent and royalty
168- puf ["s_corp_income" ] = puf .E26190 - puf .E26180 # Schedule E active S-Corp income
169- puf ["partnership_income" ] = puf .E25980 - puf .E25960 # Schedule E active partnership income
168+ s_corp_income = puf .E26190 - puf .E26180 # Schedule E active S-Corp income
169+ partnership_income = puf .E25980 - puf .E25960 # Schedule E active partnership income
170+ puf ["partnership_s_corp_income" ] = s_corp_income + partnership_income
170171 puf ["farm_operations_income" ] = puf .E02100 # Schedule F active farming operations
171- puf ["farm_rental_income " ] = puf .E27200 # Schedule E farm rental income
172+ puf ["farm_rent_income " ] = puf .E27200 # Schedule E farm rental income
172173 puf ["self_employment_income" ] = puf .E00900 # Schedule C Sole Proprietorship
173174 puf ["self_employed_health_insurance_ald" ] = puf .E03270
174175 puf ["self_employed_pension_contribution_ald" ] = puf .E03300
@@ -209,12 +210,11 @@ def preprocess_puf(puf: pd.DataFrame) -> pd.DataFrame:
209210 # --- Qualified Business Income Deduction computation and simulation ---
210211 qbi = (
211212 puf ["self_employment_income" ] # Schedule C sole prop
212- + puf ["farm_operations_income" ] # NEW: schedule F active farming ops
213- + puf ["farm_rental_income " ] # Schedule E farm rent: TODO: accidentally renamed farm_rent_income
213+ + puf ["farm_operations_income" ] # Schedule F active farming operations
214+ + puf ["farm_rent_income " ] # Schedule E farm rent
214215 + puf ["rental_income" ] # Schedule E rent and royalty
215216 + puf ["estate_income" ] # Schedule E estate and trust
216- + puf ["s_corp_income" ] # NEW: Schedule E S Corp # TODO: remake partnership_s_corp_income?
217- + puf ["partnership_income" ] # NEW: Schedule E active partnership
217+ + puf ["partnership_s_corp_income" ] # Schedule E Active S-Corp or partnership
218218 )
219219 print (f"QBI Est (Millions) New: { np .dot (qbi , puf .S006 ) / 1E6 :,.0f} " )
220220
@@ -262,38 +262,27 @@ def simulate_w2_wages_from_qualified_business(qbi, diagnostics=False):
262262 print (f"For positive wages, med ubia prop (mil): { np .median (ubia_property [w2_wages > 0 ])/ 1E6 :.1f} " )
263263 return w2_wages , ubia_property
264264
265- w2_wages , ubia_property = simulate_w2_wages_from_qualified_business (qbi )
265+ w2_wages , ubia_property = simulate_w2_wages_from_qualified_business (qbi , True )
266266 puf ["w2_wages_from_qualified_business" ] = w2_wages
267267 puf ["unadjusted_basis_qualified_property" ] = ubia_property
268268
269- # Simulate whether business is SSTB
270- largest_qbi_source = np .argmax (puf [[
271- # 0: 20% 1: 0% 2: 15% 3: 0% 4: 0%
272- "E00900" , "E02100" , "E26270" , "P25700" , "E25850" ,
273- # 5: 0% 6: 10% 7: 10% 0%
274- "E27200" , "E26390" , "E26400" , "E02000" ]], axis = 1 )
275- largest_qbi_source = np .where (qbi <= 0 , - 1 , largest_qbi_source )
276-
277- pr_sstb = np .where (largest_qbi_source == - 1 , 0 ,
278- np .where (largest_qbi_source == 0 , 0.20 ,
279- np .where (largest_qbi_source == 1 , 0.00 ,
280- np .where (largest_qbi_source == 2 , 0.15 ,
281- np .where (largest_qbi_source == 3 , 0.00 ,
282- np .where (largest_qbi_source == 4 , 0.00 ,
283- np .where (largest_qbi_source == 5 , 0.00 ,
284- np .where (largest_qbi_source == 6 , 0.10 ,
285- np .where (largest_qbi_source == 7 , 0.10 ,
286- np .where (largest_qbi_source == 8 , 0.00 ,
287- largest_qbi_source ))))))))))
288-
289- pr_sstb = np .where (qbi < 1E-3 , 0 , pr_sstb )
269+ sstb_prob_map_by_name = {
270+ "E00900" : 0.20 ,
271+ "E26270" : 0.15 ,
272+ "E26390" : 0.10 ,
273+ "E26400" : 0.10
274+ }
275+
276+ puf_qbi_sources_for_sstb = puf [sstb_prob_map_by_name .keys ()]
277+ largest_qbi_source_name = puf_qbi_sources_for_sstb .idxmax (axis = 1 )
278+
279+ pr_sstb = largest_qbi_source_name .map (sstb_prob_map_by_name ).fillna (0.0 )
290280 puf ["business_is_sstb" ] = np .random .binomial (n = 1 , p = pr_sstb )
291- print (f"SSTB %: { 100 * np .mean (puf .loc [qbi > 0 ]['business_is_sstb' ]):.1f} % of qbi pos biz " )
281+ print (f"SSTB % of >0qbi biz : { 100 * np .mean (puf .loc [qbi > 0 ]['business_is_sstb' ]):.1f} " )
292282
293283 # TODO: improve
294- puf ["reit_dividend_income" ] = 100
295- puf ["ptp_income" ] = 100 # Publically traded partnership income
296- puf ["bdc_dividend_income" ] = 100 # business development company income
284+ puf ["qualified_reit_and_ptp_income" ] = 100
285+ puf ["qualified_bdc_income" ] = 100 # business development company income
297286
298287 # -------- End QBID work -------
299288 puf ["filing_status" ] = puf .MARS .map (
@@ -326,7 +315,7 @@ def simulate_w2_wages_from_qualified_business(qbi, diagnostics=False):
326315 "estate_income" ,
327316 "farm_operations_income" ,
328317 "farm_income" ,
329- "farm_rental_income " ,
318+ "farm_rent_income " ,
330319 "health_savings_account_ald" ,
331320 "interest_deduction" ,
332321 "long_term_capital_gains" ,
@@ -339,8 +328,6 @@ def simulate_w2_wages_from_qualified_business(qbi, diagnostics=False):
339328 "real_estate_taxes" ,
340329 "rental_income" ,
341330 "self_employment_income" ,
342- "s_corp_income" ,
343- "partnership_income" ,
344331 "self_employed_health_insurance_ald" ,
345332 "self_employed_pension_contribution_ald" ,
346333 "short_term_capital_gains" ,
@@ -374,9 +361,9 @@ def simulate_w2_wages_from_qualified_business(qbi, diagnostics=False):
374361 "unadjusted_basis_qualified_property" ,
375362 "business_is_sstb" ,
376363 "deductible_mortgage_interest" ,
377- "reit_dividend_income " ,
378- "ptp_income " ,
379- "bdc_dividend_income "
364+ "partnership_s_corp_income " ,
365+ "qualified_reit_and_ptp_income " ,
366+ "qualified_bdc_income "
380367]
381368
382369
0 commit comments