I've performed a collapse to obtain a number of statistics (such as the mean and sd) for a list of assets. I then -reshape-d wide using a variable with seven categories as my j() giving me e.g. x_asset1 ... asset7 - which I want to use to create some ratios, such as:
Code:
gen asset_p1c = x_asset3 / (x_asset2 + x_asset3) gen asset_p2c = x_asset4 / (x_asset2 + x_asset4) gen asset_noc = x_asset1 / (x_asset1 + x_asset2)
Code:
local list bank super prop local suffix p1c p2c noc // refers to type of ratio foreach v of local list { foreach s of local suffix { gen `v'_`s' = x_`v'_3 / (x_`v'_2 + x_`v'_3) // ratio 1 gen `v'_`s' = x_`v'_4 / (x_`v'_2 + x_`v'_4) // ratio 2 gen `v'_`s' = x_`v'_1 / (x_`v'_1 + x_`v'_2) // ratio 3 } }
Stata v.15.1. Using panel data.
0 Response to Is it possible to add _ to the variable used in by() when collapsing to simplify ability to perform search for said variables
Post a Comment