hello statausers,
I am encountering several issues with my code and I couldn't find any problem to fix the issue.
This problem is also one of the follow-up question here: https://www.statalist.org/forums/for...erent-versions, but it's on slightly different issue.
In particular, Im trying 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:
But i have the following error message:
I assure that it's not the problem on data or regression, but it's really on the command itself.
In addition, it's also on the same issue from previous post above: not all the 4 regressions of aggregated version are exported, but only the column 4 is survived + rest of non-aggregated version.
If someone has any insights on this issue again, I would appreciate a lot for your help! (but the main issue here is on the command with error message)
Could someone have any idea/insights on this issue, please?
Thanks so much in advance!
I am encountering several issues with my code and I couldn't find any problem to fix the issue.
This problem is also one of the follow-up question here: https://www.statalist.org/forums/for...erent-versions, but it's on slightly different issue.
In particular, Im trying 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:
* Choose dataset to use loc dataset 1 // 1 if MainStat; 0 if 10plus if `dataset' { // MainStat loc data_use Quant gl folder ${Mainfolder} } else { // 10plus loc data_use 10plus gl folder ${tenplusfolder} } use "~directory/`data_use'.dta", clear * Generating variables / Basic setup for varlist F5*_av : cap replace X = 5*X keep if inrange(p_LogLP_VA,1,5) keep if inlist(ind_a7, 3, 6) drop if inlist(ind_a38, 19, 68) gen keepcountry = 0 foreach country in $countryList { replace keepcountry=1 if country=="`country'" } keep if keepcountry drop keepcountry loc indlvl ind_a38 foreach wvar in L VA GO { * weighting variable cap egen `wvar'_cy = total(`wvar'_av * `wvar'_sum_w) if `wvar'_av >= 0, by(country year) cap gen `wvar'_sh_`indlvl' = `wvar'_av * `wvar'_sum_w / `wvar'_cy if `wvar'_av >= 0 cap drop `wvar'_cy } ren L_sh_ind_a38 _w loc prodvar LogLP_VA cap drop cell_share gen cell_share = 10 if inlist(p_`prodvar',1,5) replace cell_share = 30 if inlist(p_`prodvar',2,4) replace cell_share = 20 if p_`prodvar' == 3 gen weightvar = cell_share * _w gen Covid = 1 if year >= 2015 replace Covid = 0 if year < 2015 * Regression cap encode country, gen(cty) loc analysislevel 1 // 1 if one-by-one (country); 0 if excluding one country if `analysislevel' { loc regif "==" } else { loc regif "!=" } levelsof country, local(countries) local iteration 1 foreach c of local countries { if `iteration' == 1 local replace_op replace if `iteration' > 1 local replace_op append noi di _n "Country: `c'" if `analysislevel' { loc ex_lab } else { loc ex_lab "Excluding, `c'," } loc LHS F5LogW_av loc model_name "`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 RHS for columns 1&2 // 3&4 if inlist(`col', 1, 2) local xvars ib3.p_LogLP_VA LogW_av // Columns 1&2 else local xvars F1LogLP_VA_av ib3.p_LogLP_VA F1LogW_av LogW_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 `LHS' `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}/`analysislevel'_Baseline.xls", `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 forval col local ++iteration } // end of countries loop
Code:
Country: CAN Unexpected regression error: var = , country = CAN Unexpected regression error: var = , country = CAN Unexpected regression error: var = , country = CAN Unexpected regression error: var = , country = CAN Country: FIN Unexpected regression error: var = , country = FIN Unexpected regression error: var = , country = FIN Unexpected regression error: var = , country = FIN Unexpected regression error: var = , country = FIN Country: FRA Unexpected regression error: var = , country = FRA Unexpected regression error: var = , country = FRA Unexpected regression error: var = , country = FRA Unexpected regression error: var = , country = FRA Country: HRV Unexpected regression error: var = , country = HRV Unexpected regression error: var = , country = HRV Unexpected regression error: var = , country = HRV Unexpected regression error: var = , country = HRV Country: ITA Unexpected regression error: var = , country = ITA Unexpected regression error: var = , country = ITA Unexpected regression error: var = , country = ITA Unexpected regression error: var = , country = ITA Country: LTU Unexpected regression error: var = , country = LTU Unexpected regression error: var = , country = LTU Unexpected regression error: var = , country = LTU Unexpected regression error: var = , country = LTU Country: PRT Unexpected regression error: var = , country = PRT Unexpected regression error: var = , country = PRT Unexpected regression error: var = , country = PRT Unexpected regression error: var = , country = PRT Country: SVN Unexpected regression error: var = , country = SVN Unexpected regression error: var = , country = SVN Unexpected regression error: var = , country = SVN Unexpected regression error: var = , country = SVN
In addition, it's also on the same issue from previous post above: not all the 4 regressions of aggregated version are exported, but only the column 4 is survived + rest of non-aggregated version.
If someone has any insights on this issue again, I would appreciate a lot for your help! (but the main issue here is on the command with error message)
Could someone have any idea/insights on this issue, please?
Thanks so much in advance!
Comment