I am trying to export tables from stata to word using putexcel, where the row and column variables have value labels. However, after using the matlist command, the frequencies are not reported correctly
I have used the following commands to proceed towards using putexcel to transfer the results to stata
As I have shown from the output above, the tabulate option frequencies are not rendered after I use the matlist code. The string variables for sect and edulevel are ordered alphabetically rather than what the initial table says. Thus, the frequencies are jumbled up. For instance in the first row, for agriculture, the tabulate option shows that frequency for primary educated is 1383, while after the matlist command, it shows that frequency for Higher educated is 1383 instead.
I require some help regarding correct alignment of the data in the tables. Any help would be really appreciated.
Code:
. tab sect edulevel, matcell(cellcounts) | edulevel sect | Below Pri Primary middle | Total ----------------------+---------------------------------+---------- Agriculture | 4,213 1,383 1,545 | 8,555 Forestry and Fishing | 84 77 104 | 403 Mining | 118 64 131 | 551 Food manuf | 207 144 292 | 1,125 Textile and leather m | 350 386 618 | 2,359 Wood Manuf | 107 71 178 | 523 Media Printing and Re | 6 19 58 | 199 Chemicals Manuf | 91 82 203 | 1,078 Non-metal Manuf | 193 77 168 | 693 Basic Metal Manuf | 65 64 119 | 661 Machinery manuf | 87 91 171 | 640 Electronics Manuf | 5 7 19 | 148 Equipt Manuf | 68 102 235 | 1,197 Furniture Manuf | 59 75 150 | 432 Manuf Others | 47 77 149 | 458 Repair & install mach | 25 38 103 | 354 Elec & Gas Supply | 38 29 115 | 594 Sanitation Services | 61 44 88 | 338 Construction | 2,877 1,612 2,544 | 9,253 Civil Engineering | 219 148 199 | 940 Special Construction | 246 268 570 | 1,676 Wholesale | 180 177 420 | 1,877 Retail | 253 329 1,014 | 3,689 Land & Pipeline Trans | 456 470 1,109 | 3,495 Transportation & post | 62 46 144 | 742 Tourism | 240 208 378 | 1,418 Media, Telecom & IT | 15 10 73 | 1,290 Finance Legal & Mktg | 33 59 277 | 3,081 Real Estate | 7 3 12 | 69 Architect. & Engineer | 0 2 1 | 95 R&D | 3 2 4 | 49 Veterinary | 0 2 5 | 53 Employment | 6 3 15 | 63 Security and Building | 92 72 201 | 677 Public Admin | 181 167 617 | 4,111 Education | 188 180 421 | 6,591 Health svs | 69 55 251 | 1,843 Resid & social Worker | 48 37 75 | 444 Art & entertain. | 32 26 58 | 226 Organizations | 33 32 82 | 335 Repair and personal s | 221 114 159 | 802 Domestic Personnel | 816 335 460 | 1,966 ----------------------+---------------------------------+---------- Total | 12,101 7,187 13,535 | 65,093 | edulevel sect | secondary Higher Se Higher | Total ----------------------+---------------------------------+---------- Agriculture | 875 391 148 | 8,555 Forestry and Fishing | 62 47 29 | 403 Mining | 81 64 93 | 551 Food manuf | 195 140 147 | 1,125 Textile and leather m | 499 281 225 | 2,359 Wood Manuf | 74 46 47 | 523 Media Printing and Re | 48 17 51 | 199 Chemicals Manuf | 182 179 341 | 1,078 Non-metal Manuf | 99 68 88 | 693 Basic Metal Manuf | 135 110 168 | 661 Machinery manuf | 121 78 92 | 640 Electronics Manuf | 16 19 82 | 148 Equipt Manuf | 191 184 417 | 1,197 Furniture Manuf | 94 41 13 | 432 Manuf Others | 89 56 40 | 458 Repair & install mach | 80 45 63 | 354 Elec & Gas Supply | 106 104 202 | 594 Sanitation Services | 61 39 45 | 338 Construction | 1,395 571 254 | 9,253 Civil Engineering | 137 66 171 | 940 Special Construction | 315 159 118 | 1,676 Wholesale | 317 284 499 | 1,877 Retail | 772 658 663 | 3,689 Land & Pipeline Trans | 737 387 336 | 3,495 Transportation & post | 135 156 199 | 742 Tourism | 225 167 200 | 1,418 Media, Telecom & IT | 89 120 983 | 1,290 Finance Legal & Mktg | 303 425 1,984 | 3,081 Real Estate | 8 11 28 | 69 Architect. & Engineer | 2 2 88 | 95 R&D | 4 2 34 | 49 Veterinary | 10 7 29 | 53 Employment | 5 8 26 | 63 Security and Building | 138 98 76 | 677 Public Admin | 716 890 1,540 | 4,111 Education | 537 844 4,421 | 6,591 Health svs | 241 328 899 | 1,843 Resid & social Worker | 97 78 109 | 444 Art & entertain. | 29 27 54 | 226 Organizations | 60 46 82 | 335 Repair and personal s | 133 97 78 | 802 Domestic Personnel | 184 86 85 | 1,966 ----------------------+---------------------------------+---------- Total | 9,597 7,426 15,247 | 65,093
Code:
decode sect, g(sect_s) levelsof sect_s, local(namesec) "Agriculture"' `"Architect. & Engineer"' `"Art & entertain."' `"Basic Metal Manuf"' `"Chemicals Manuf"' `"Civil Engineering"' `"Construction"' `"Domestic Personnel"' `"Education"' `"Elec & Gas Supply"' `"Electronics Manuf"' `"Employment"' `"Equipt Manuf"' `"Finance Legal & Mktg Corp Svs"' `"Food manuf"' `"Forestry and Fishing"' `"Furniture Manuf"' `"Health svs"' `"Land & Pipeline Transport"' `"Machinery manuf"' `"Manuf Others"' `"Media Printing and Records"' `"Media, Telecom & IT"' `"Mining"' `"Non-metal Manuf"' `"Organizations "' `"Public Admin"' `"R&D"' `"Real Estate"' `"Repair & install machinery"' "Repair and personal svs"' `"Resid & social Workers"' `"Retail"' `"Sanitation Services"' `"Security and Building svs"' `"Special Construction"' `"Textile and leather manuf"' `"Tourism"' `"Transportation & postal"' `"Veterinary"' `"Wholesale"' `"Wood Manuf"' matrix rownames cellcounts = `namesec' .decode edulevel, g(edu_s) . levelsof edu_s, local(edu) `"Below Primary"' `"Higher"' `"Higher Secondary"' `"Primary"' `"middle"' `"sec > ondary"' . matrix colnames cellcounts = `edu' . matlist cellcounts | Below P~y Higher Higher ~y Primary middle -------------+------------------------------------------------------- Agriculture | 4213 1383 1545 875 391 Architect.~r | 84 77 104 62 47 Art & ente~. | 118 64 131 81 64 Basic Meta~f | 207 144 292 195 140 Chemicals ~f | 350 386 618 499 281 Civil Engi~g | 107 71 178 74 46 Construction | 6 19 58 48 17 Domestic P~l | 91 82 203 182 179 Education | 193 77 168 99 68 Elec & Gas~y | 65 64 119 135 110 Electronic~f | 87 91 171 121 78 Employment | 5 7 19 16 19 Equipt Manuf | 68 102 235 191 184 Finance Le~s | 59 75 150 94 41 Food manuf | 47 77 149 89 56 Forestry a~g | 25 38 103 80 45 Furniture ~f | 38 29 115 106 104 Health svs | 61 44 88 61 39 Land & Pip~t | 2877 1612 2544 1395 571 Machinery ~f | 219 148 199 137 66 Manuf Others | 246 268 570 315 159 Media Prin~s | 180 177 420 317 284 Media, Tel~T | 253 329 1014 772 658 Mining | 456 470 1109 737 387 Non-metal ~f | 62 46 144 135 156 Organizati~s | 240 208 378 225 167 Public Admin | 15 10 73 89 120 R&D | 33 59 277 303 425 Real Estate | 7 3 12 8 11 Repair & i~y | 0 2 1 2 2 Repair and~s | 3 2 4 4 2 Resid & so~s | 0 2 5 10 7 Retail | 6 3 15 5 8 Sanitation~s | 92 72 201 138 98 Security a~s | 181 167 617 716 890 Special Co~n | 188 180 421 537 844 Textile an~f | 69 55 251 241 328 Tourism | 48 37 75 97 78 Transporta~l | 32 26 58 29 27 Veterinary | 33 32 82 60 46 Wholesale | 221 114 159 133 97 Wood Manuf | 816 335 460 184 86 | secondary -------------+----------- Agriculture | 148 Architect.~r | 29 Art & ente~. | 93 Basic Meta~f | 147 Chemicals ~f | 225 Civil Engi~g | 47 Construction | 51 Domestic P~l | 341 Education | 88 Elec & Gas~y | 168 Electronic~f | 92 Employment | 82 Equipt Manuf | 417 Finance Le~s | 13 Food manuf | 40 Forestry a~g | 63 Furniture ~f | 202 Health svs | 45 Land & Pip~t | 254 Machinery ~f | 171 Manuf Others | 118 Media Prin~s | 499 Media, Tel~T | 663 Mining | 336 Non-metal ~f | 199 Organizati~s | 200 Public Admin | 983 R&D | 1984 Real Estate | 28 Repair & i~y | 88 Repair and~s | 34 Resid & so~s | 29 Retail | 26 Sanitation~s | 76 Security a~s | 1540 Special Co~n | 4421 Textile an~f | 899 Tourism | 109 Transporta~l | 54 Veterinary | 82 Wholesale | 78 Wood Manuf | 85 .
I require some help regarding correct alignment of the data in the tables. Any help would be really appreciated.