Dear Stata Users
I am using a very large survey dataset from PISA 2022 to estimate the determinants of students' performance in mathematics. I have estimated the regressions using the following codes and attempted to export the results to word. The following is my code for the estimations. In essence, I estimate regressions for all 10 outcome variables in measuring mathematics performance and average the coefficients to get the final results. Someone helped me with this code, and I can't speak much about it, since I don't have a background in coding. However, my main problem for now is that the second part of the code which aims to export the results to Word, is failing, and that is where I need assistance.
When I attempt to export results using this code, it fails. There are several errors ranging from ereturn post b se_avg: conformability error; in fact the entire code fails and I basically fail to export the results.
My data example
I look forward to your assistance.
I am using a very large survey dataset from PISA 2022 to estimate the determinants of students' performance in mathematics. I have estimated the regressions using the following codes and attempted to export the results to word. The following is my code for the estimations. In essence, I estimate regressions for all 10 outcome variables in measuring mathematics performance and average the coefficients to get the final results. Someone helped me with this code, and I can't speak much about it, since I don't have a background in coding. However, my main problem for now is that the second part of the code which aims to export the results to Word, is failing, and that is where I need assistance.
Code:
* Full process with esttab svyset CNTSCHID [pweight=W_FSTUWT], strata(STRATUM) fay(.5) vce(brr) brrweight(W_FSTURWT1-W_FSTURWT80) singleunit(certainty) forvalues i = 1/10 { quietly svy: regress PV`i'MATH ST004D01T ESCS MATHMOT ANXMAT matrix beta`i' = e(b) matrix var`i' = e(V) } matrix beta_avg = J(1,5,0) forvalues i = 1/10 { matrix beta_avg = beta_avg + beta`i' / 10 } matrix var_within = J(5,5,0) forvalues i = 1/10 { matrix var_within = var_within + var`i' / 10 } matrix var_between = J(5,5,0) forvalues i = 1/10 { matrix diff = beta`i' - beta_avg matrix var_between = var_between + diff' * diff / 9 } matrix var_total = var_within + var_between * (1 + 1/10) matrix se = vecdiag(var_total) mata se = sqrt(st_matrix("se")) st_matrix("se", se) end
When I attempt to export results using this code, it fails. There are several errors ranging from ereturn post b se_avg: conformability error; in fact the entire code fails and I basically fail to export the results.
Code:
matrix b = beta_avg matrix se_avg = se ereturn post b se_avg eststo model1 estadd scalar N = 49406 estadd scalar r2 = 0.0846 estadd scalar F = 129.74 esttab model1 using "pisa_math_results.rtf", /// b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) /// mtitles("Math Performance") /// varlabels(ST004D01T "Gender (Female=1)" ESCS "Socioeconomic Status" MATHMOT "Math Motivation" ANXMAT "Math Anxiety" _cons "Constant") /// stats(N r2 F, fmt(0 3 2) labels("Observations" "R-squared" "F-statistic")) /// note("Notes: Standard errors in parentheses. Significance: * p<0.10, ** p<0.05, *** p<0.01. Results averaged across 10 plausible values using Rubin’s rules.") /// title("Table 1: Determinants of Mathematics Performance (PISA 2022)") /// replace
My data example
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double(CNTRYID CNTSCHID CNTSTUID PV1MATH PV2MATH PV3MATH PV4MATH PV5MATH PV6MATH PV7MATH PV8MATH PV9MATH PV10MATH ST004D01T ESCS MATHMOT ANXMAT) 8 800001 800296 555.339 521.11 527.583 510.497 556.943 521.028 555.707 452.851 532.09 549.882 2 .2654 0 -.755 8 800001 800385 384.794 277.04 335.525 358.538 425.36 346.933 371.468 391.83 359.364 377.692 1 -2.613 0 .6566 8 800001 800431 448.413 399.589 370.993 448.702 444.942 393.753 500.593 403.966 410.613 420.181 1 -.4878 0 -.7107 8 800001 800505 382.478 352.507 346.608 355.846 417.014 306.109 391.885 307.213 380.475 386.568 2 -1.3323 0 -.6243 8 800001 800592 269.435 261.008 291.362 346.57 279.107 243.505 240.278 229.055 307.837 312.469 2 .4677 0 -.0401 8 800001 800783 376.313 428.577 418.476 378.812 416.409 369.165 343.23 388.927 406.931 430.299 1 -1.0041 0 . 8 800001 800902 390.765 371.139 411.263 410.307 407.626 365.434 298.473 379.532 395.026 376.291 1 -.7437 0 .133 8 800001 801080 306.966 314.009 305.426 323.346 239.525 292.601 348.11 299.208 369.734 266.036 2 -1.4753 1 .44 8 800001 801101 419.804 379.962 421.836 470.323 394.314 387.048 433.765 407.814 389.149 449.498 1 -.4284 0 .8918 8 800001 801271 411.141 339.656 360.292 382.239 373.289 356.013 358.493 397.485 370.417 370.008 1 -.2731 0 -.6243 8 800001 801394 252.81 358.824 283.563 239.745 204.688 274.598 229.007 223.659 249.371 275.749 1 -2.9161 0 2.6109 8 800001 802088 541.944 410.327 368.528 500.833 532.788 427.694 451.533 462.837 478.585 589.076 1 .3264 0 -.508 8 800001 802098 408.497 435.493 418.53 410.673 377.129 408.453 417.992 444.109 428.553 460.284 2 -1.8732 0 1.9128 8 800001 802361 243.386 231.753 251.077 273.971 295.839 235.032 306.954 305.607 288.371 297.487 1 -2.2675 0 .602 8 800001 802831 464.877 448.598 447.615 464.561 497.792 464.156 479.769 462.428 438.39 478.165 2 .2406 0 -2.3945 8 800001 802889 461.526 489.755 494.461 519.803 492.05 504.897 518.61 454.013 514.585 491.051 2 -.8382 0 -.1172 8 800001 803162 484.392 520.18 489.347 553.609 498.878 541.367 482.047 522.157 498.667 523.032 2 .1893 0 -.9158 8 800001 803197 416.375 450.441 398.307 330.273 441.332 341.644 356.972 363.966 424.923 356.637 1 -.257 0 1.1287 8 800001 803364 503.104 528.83 517.401 540.319 529.696 489.027 586.874 537.09 540.408 556.895 1 -1.601 0 -.9158 8 800001 803477 395.918 448.428 380.122 384.098 383.963 426.829 416.329 412.158 449.01 440.139 1 -1.2213 0 .6387 8 800001 803535 267.773 304.921 294.213 297.104 313.097 322.259 298.607 303.741 325.008 303.598 1 -1.3056 0 1.1606 8 800001 803546 353.756 405.78 361.589 363.381 398.651 406.704 359.963 354.319 383.711 376.493 2 -1.2863 0 -.3744 8 800001 803889 504.422 488.583 399.489 441.604 438.691 456.971 440.828 473.952 444.046 438.125 1 .2687 0 -2.3755 8 800001 803944 440.187 405.278 452.014 413.599 402.809 390.635 404.378 410.086 433.784 421.286 2 .6568 0 2.635 8 800001 804038 408.345 405.786 413.788 394.102 450.236 382.314 409.802 393.38 437.697 414.073 1 .4374 0 1.1287 8 800001 804064 245.076 351.723 260.283 306.452 293.943 345.784 323.431 302.569 244.224 236.015 2 -.9386 0 .8251 8 800001 804365 570.97 590.143 539.372 611.083 582.432 536.515 591.657 555.103 537.76 558.392 2 .3225 0 -.6243 8 800001 804817 346.817 378.438 351.505 322.261 343.878 326.189 262.985 363.656 320.762 331.981 2 -.8007 0 .7889 8 800001 805224 357.831 323.97 324.867 329.744 306.568 396.286 280.25 287.31 273.809 299.444 2 -1.351 . . 8 800001 805752 419.147 449.714 465.089 483.972 451.425 465.388 523.971 484.866 434.522 482.397 1 -.4654 0 -.9979 8 800001 806268 294.622 287.042 256.501 281.984 251.432 200.421 312.781 280.983 250.603 205.837 2 -.0889 0 .8251 8 800001 806387 376.905 397.098 371.625 408.855 414.889 393.129 440.483 434.09 390.619 398.64 1 -1.3209 0 -.0394 8 800001 806469 317.442 313.298 295.488 304.367 326.769 327.469 320.524 325.802 311.083 352.889 1 -.1445 0 -.0401 8 800001 806595 438.091 446.369 441.168 404.818 451.01 483.883 480.019 466.251 430.615 444.077 1 -.0468 0 .6647 8 800001 806618 233.751 324.568 223.943 336.978 311.132 271.959 237.116 263.515 256.479 246.991 1 -2.1627 0 -.3744 8 800001 806650 470.109 458.283 511.577 472.788 426.63 419.98 447.194 454.061 447.735 444.832 1 -1.173 0 .3025 8 800001 806811 464.829 380.831 463.978 483.348 379.315 425.443 482.493 485.762 491.47 475.196 1 -1.5296 0 -.4577 8 800001 806822 247.31 253.14 194.995 326.674 244.345 274.105 263.707 259.206 256.074 275.798 2 -.4881 . .8251 8 800001 806839 402.382 392.279 423.917 432.201 371.444 381.695 390.74 421.188 393.616 400.375 2 . . . 8 800001 807191 419.214 329.973 427.053 435.429 409.373 376.111 425.328 405.006 383.008 387.929 1 .394 0 .4067 8 800001 807212 428.476 440.855 379.999 410.959 343.722 406.338 422.322 382.842 416.9 397.409 1 .3632 0 -2.3016 8 800002 800175 452.453 424.127 435.895 432.201 412.247 435.819 449.899 411.437 413.821 431.556 1 -.6308 0 -.0575 8 800002 800254 440.819 458.535 456.865 484.589 427.851 431.158 478.81 454.301 409.762 479.585 2 -1.16 0 -1.1715 8 800002 800863 363.205 427.236 392.141 356.693 318.328 351.073 364.922 378.195 347.421 357.696 2 .4129 0 . 8 800002 800883 348.902 432.789 410.503 431.822 408.614 406.927 423.388 399.476 412.221 399.263 2 1.3225 0 -.5006 8 800002 801056 386.995 384.952 452.247 452.572 518.986 409.993 362.752 474.497 417.898 414.531 1 .2622 0 .8251 8 800002 801109 401.94 413.246 374.146 383.544 314.219 344.243 418.126 408.544 429.762 408.232 1 -1.1849 0 -.3794 8 800002 801159 328.154 216.1 266.559 270.23 238.724 293.031 237.275 244.614 223.064 271.102 2 -2.0074 . -.3395 8 800002 801174 271.649 314.878 327.411 281.117 370.61 337.385 267.971 313.189 348.004 297.173 1 -2.5835 0 1.2595 8 800002 802128 410.765 444.1 376.923 361.224 288.977 316.953 273.17 309.006 339.683 314.758 1 -.9616 0 1.1417 end label values CNTRYID CNTRYID label def CNTRYID 8 "Albania", modify label values ST004D01T ST004D01T label def ST004D01T 1 "Female", modify label def ST004D01T 2 "Male", modify label values ESCS ESCS label values MATHMOT MATHMOT label def MATHMOT 0 "Not more motivated to do well in mathematics than other subjects", modify label def MATHMOT 1 "More motivated to do well in mathematics than other subjects", modify label values ANXMAT ANXMAT
Comment