I'm trying to write a loop where I have reporter and partner countries and country groupings as separate variables and want to collapse and create new variables. The local is the country groupings and then I've tried to loop but get "var not found". Anyone have advice? Thanks in advance.
local country_groups EU advanced advanced_no_US_EU advanced_no_Taiwan EMs EMs_no_PRC_RUS EMs_no_PRC developing other_middle_income non_advanced non_advanced_no_PRC middle_income middle_income_no_PRC
foreach var in local country_groups {
preserve
collapse (sum) trade_world trade_PRC trade_US trade_PRC_US total_trade total_trade_HS if x==1, by(HS_chapter year)
gen reporter="var"
*China trade share
gen trade_share_PRC=trade_PRC/trade_world
*US trade share
gen trade_share_US=trade_US/trade_world
*China trade/China+US trade
gen trade_share_PRC_US=trade_PRC/trade_PRC_US
save `x'_US_PRC, replace
}
Related Posts with Loop for collapse + save file
Performing operations by values of a specific unit, by yearHi All, I have data that resembles the following: Code: * Example generated by -dataex-. To ins…
Help on -mswitch- command to estimate Markov Switching Regression ModelsHello, I use Stata 14. I have a panel dataset. I want to estimate for each id/country in the panel d…
Difference-in-difference with three time periodsDear all, I am trying to estimate the difference of impact of the Athenes Olympic and the Paralympi…
Firm FE and firm registration type FEDear friends, I would like to analyze the effect of a policy on the number of patents using the Dif…
Variable Significance Changes After Adding Regional DummiesDear All, I have two simple yet complicated question. I run my regressions on survey data using th…
Subscribe to:
Post Comments (Atom)
0 Response to Loop for collapse + save file
Post a Comment