Hello statausers,
I am working on generating regression tables with nested loop - for different versions - and it is also one of the follow-up questions: https://www.statalist.org/forums/for...t-observations.
In particular, I would like to export regression tables in excel file in which it contains: Columns (1) to (4) are so-called "Aggregated" version and columns from (5) until the end is either version 0 or 1.
Aggregated version is when every country is included in the regression, 0 is when one country is excluded from the dataset at the time (for e.g. if countrylist is USA, UK, FRA, CAN then first set is excluding only USA, second set is UK, and so on), and 1 is when we are regressing one-by-one country (for e.g. only USA, then UK, then FRA so on).
To implement this, i used the following command:
However, i get the following error:
I am unsure where to find the issues.. and to fix them eventually.
I understand that my code is a bit complicated but hope the question is clear!
Thanks a lot in advance.
I am working on generating regression tables with nested loop - for different versions - and it is also one of the follow-up questions: https://www.statalist.org/forums/for...t-observations.
In particular, I would like to export regression tables in excel file in which it contains: Columns (1) to (4) are so-called "Aggregated" version and columns from (5) until the end is either version 0 or 1.
Aggregated version is when every country is included in the regression, 0 is when one country is excluded from the dataset at the time (for e.g. if countrylist is USA, UK, FRA, CAN then first set is excluding only USA, second set is UK, and so on), and 1 is when we are regressing one-by-one country (for e.g. only USA, then UK, then FRA so on).
To implement this, i used the following command:
Code:
gl folder folderdirectory cap encode country, gen(cty) loc job var1 var2 var3 var4 loc analysislevel 0 // 1 if one-by-one (country); 0 if excluding one country loc iteration 1 levelsof country, local(countries) foreach c in "" `countries' { * Excel file replace/append option if `iteration' == 1 local replace_op replace if `iteration' > 1 local replace_op append * Regression versions: Aggregate + 0/1 if missing("`c'") { // Aggregate loc regif loc ex_lab loc cn Aggregate } if `analysislevel' { // 1; one-by-one loc regif "if country =="`c'"" loc ex_lab loc cn `c' } else { // 0; excluding loc regif "if country !="`c'"" loc ex_lab "Excluding, "`c'"," loc cn `c' } noi di _n "================= Country: `cn' ===================" foreach var of local job { * Basic setup for regression loc model_name "5-year `var'" loc FElbl13 i.cty#i.year i.cty#i.ind_a38 loc FElbl24 i.cty#i.ind_a38#i.year loc FE13 "C-I C-Y" loc FE24 "C-I-Y" loc cl_CI i.cty#i.ind_a38 * Regression (Columns 1 to 4) forval col = 1/4 { * Setting regressors for columns 1&2 // 3&4 if inlist (`col', 1, 2) local xvars ib3.p_LogLP_VA LogL_av // Columns 1&2 else local xvars F1LogLP_VA_av ib3.p_LogLP_VA `var'_1L LogL_av // Columns 3&4 * Setting FE/labels for columns 1&3 // 2&4 if inlist(`col', 1, 3) local fe `FElbl13' local fe_table `FE13' else local fe `FElbl124' local fe_table `FE24' * REGRESSION capture reghdfe `var'_5L `xvars' `regif' [aw=weightvar], a(`fe') vce(cluster `cl_CI') if c(rc) == 0 { levelsof country if e(sample), clean local(countrylist) local n_countries = `r(r)' levelsof ind_a38 if e(sample) local n_inds = `r(r)' * Export to excel file outreg2 using "${folder}/Baseline/`analysislevel'_`var'.xlsx", `replace_op' ctitle(`model_name') label /// addtext(Fixed effects, `fe_table', Country List, `countrylist', `ex_lab' Countries, `n_countries', Industries, `n_inds') } else if !inlist(c(rc), 2000, 2001) { display as error `"Unexpected regression error: var = `var', country = `c'"' } } } // end of job loop local ++iteration } // end of countries loop
Code:
================= Country: =================== inlist not found r(111);
I understand that my code is a bit complicated but hope the question is clear!
Thanks a lot in advance.
Comment