I have the following nested for loops to run the same calculation for different radii, I have bolded the problematic line, since there's a lot of surrounding code, but since it's in a loop I thought it might be relevant:
* Outside for loop runs HHI calculations for each radii of interest
foreach radi in 50 30 20 10 {
use ${SS}ICD_Chapter_distances_`radi'.dta, clear
* This for loop calculates the HHI for each (4) relevant ICD chapter for each hospital using the current radii.
foreach chapt of varlist Chapter_2_KH2 Chapter_9_KH2 Chapter_13_KH2 Chapter_19_KH2 {
egen sum_`chapt' = sum(`chapt'), by (ID_count) /* Calculates total number of ICD chapter cases in market */
gen prop1_`chapt' = (`chapt' / sum_`chapt')
gen prop2_`chapt' = (prop1_`chapt')^2 /* Calculates the hospital's proportion of cases in it's market, then squares it */
egen HHI_`chapt' = sum(prop2_`chapt'), by (ID_count) /* Sums squared proportions to give HHI */
* Next we calculate the distance-weighted HHI
gen distProp_`chapt' = distance / `radi' /* Calculates percentage of how far away hospital is out of the radius */
gen weighted_`chapt' = `chapt' * (1 - distProp) /* Weights chapter cases by multiplying them by 1 minus the distance proportion */
egen wSum_`chapt' = sum(weighted_`chapt'), by (ID_count) /* Sum these weighted cases to get distance-weighted market total */
gen wProp_`chapt' = weighted_`chapt' / wSum_`chapt' /* Calculates weighted proportions */
gen wProp2_`chapt' = (wProp_`chapt') ^ 2 /* Squares these proportions */
egen weightedHHI_`chapt' = sum(wProp2_`chapt'), by (ID_count)
}
I receive the error "distProp" not found, which is strange to me since that shouldn't even be considered a complete variable name since I have the _`chapt' attached to it, just like I do when creating my other variables. The first calculation runs fine on it's own, so I don't know why stata can't figure out that "distProp_`chapt'" should become, for example: distProp_chapter_2_KH2, when it's able to do that earlier. I've tried changing it to dstPrp, distanceP, and whatever, all of which yield the same results. I've also tried initializing the variable to zero first and then replacing it, but that does not work either.
Any help is quite appreciated, thank you!
Related Posts with Variable not found (after others created in the same way)
Solve Macroeconometrics Model and ForecastI am trying to solve a macroeconometrics model of my country using STATA. Model has 7 endogenous var…
T Tests and Wilcoxon Tests export to MS Word or MS ExcelHello Members I had been working on EViews for some time, I shifted to Stata now, since I am new, I…
Complex Reshape Long to WideDear Stata Users I am dealing with a complex reshape wide problem. Here is an input data: Code: …
multicollinearity test variables in a panel dataHi, how can I run a multicollinearity test in Stata 12 between variables in a panel data? Thanks! …
problem with Ivreg2 resultDear All, After running my regression with ivreg2, in last portion of the result I saw error massage…
Subscribe to:
Post Comments (Atom)
0 Response to Variable not found (after others created in the same way)
Post a Comment