Hello there,

I have a monthly dataset (6 dependent variables and 5 independent variables) for 23 countries and I need to estimate the coefficients for each country and want to store the coefficients from each regression in a .csv file. I can do it country by country but looking for something that make it quicker as I have to run regressions for different models (like CAPM, FF3 etc.) for each country. I appreciate if I can get some guidance on this. I am using the below code to do the analysis for each country.

Code:
newey2 P1 if COUNTRY_ID==1, lag(1) force
est store t1

newey2 P2 if COUNTRY_ID==1, lag(1) force
est store t2

newey2 P3 if COUNTRY_ID==1, lag(1) force
est store t3

newey2 P4 if COUNTRY_ID==1, lag(1) force
est store t4

newey2 P5 if COUNTRY_ID==1, lag(1) force
est store t5

newey2 DIFF  if COUNTRY_ID==1, lag(1) force 
est store t6

esttab t1 t2 t3 t4 t5 t6 using table_1.csv, replace compress nogaps 


/**CAPM**/

newey2 P1 EX_MKT if COUNTRY_ID==1, lag(1) force
est store t1

newey2 P2 EX_MKT if COUNTRY_ID==1 , lag(1) force
est store t2

newey2 P3 EX_MKT  if COUNTRY_ID==1, lag(1) force
est store t3

newey2 P4 EX_MKT if COUNTRY_ID==1, lag(1) force
est store t4

newey2 P5 EX_MKT if COUNTRY_ID==1, lag(1) force
est store t5

newey2 DIFF EX_MKT if COUNTRY_ID==1, lag(1) force
est store t6

esttab t1 t2 t3 t4 t5 t6 using table_1.csv,append compress nogaps

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte COUNTRY_ID int YEAR byte MONTH double(P1 P2 P3 P4 P5 diff smb hml wml mkt_ex cma)

1 2019  3    .0046125873465531   .00862875632323654     .0414496128208215   .00648962358578197    .00921014654825113    -.0079894971836139  -.00654232826762831    .00914056808082754      .005944282428163             .002449859     .0417429304601078
1 2019  4   -.0200811201597907 -.000570887107893204   -.00841577172282152  -.00313611888553171   -.00463330975736689   -.00749475810364832   .00693676137211818    .00284333493766637     -.024026936230836             .013503434    -.0161460729988759
1 2019  5    .0193912527863333   .00626808138836978      .016337365594267   .00155661727199572   -.00327927108100917    .00379300828156456  -.00355377995639226    .00331036007041749    .00545194559329726             .000306771     .0217593647467235
1 2019  6     .023075555127377  -.00722618595870524     .0478838546476861    .0272504490307359     .0111945955358725    .00610351243332188   -.0354433669548342     -.012749908486037    -.0153574298199428             .043778207    .00937689193405734
1 2019  7   -.0169197893045661  -.00272634816081206     .0031771818099846  -.00646621913632429    .00923926374516304   .000562945754623201    .0110223661976976   -.00292990572120788    -.0222905826727607             .010644588     .0285256779819983
1 2019  8   -.0139292037600198    .0123210319737988      .015645945156333   -.0062836906758155  -.000336172947870854    .00256102293180176   .00680277839797479    -.0156101020061085     -.013109905969141            -.044229581     .0269397377275481
1 2019  9    -.014923369637657  .000298235296743559    -.0405958524719685   -.0114662231709203    -.0198074343026395   .000613715465678387    .0147981553933894     .0138377364986675     .0258281582400319             .022055793    -.0510695688856777
1 2019 10    .0110418125824422  -.00282259751531271    -.0172779650942185    .0118689337828983     .0149736006884741   -.00740909774721965   .00871739181545646  -.000429136276856071    .00580545282855832             .015648325     .0139315583269549
1 2019 11     .011251437954085  -.00600685507729166     -.024329847043514    .0167616273877521     .0251904535939062   -.00105697991864909   -.0228777178666771    -.0110826175381463  -.000497534789527258             .005710054  -.000272012271358907
1 2019 12  .000119667434463182   -.0217218973885073    -.0046956757456945   .00372066935470081   -.00226644803078721   .000600423774953595    .0189899016307933     .0135996354790515    .00447916414396331             .019040705   -.00385071270080288
1 2020  1  -.00801458769545551   -.0113125220164923     .0287744498667976   .00710364495987772     .0126653447215122   -.00713125261333136    -.028364698901886   -.00195089594009969    -.0261050310500236            -.003032602      .011753756750792
1 2020  2  -.00072995846856231   .00862432024265116    .00434456865201592  -.00439334554342077   -.00435683317464426    -.0100081661434567   -.0093248050963263   -.00450797045905604    .00611916591630405            -.111233795     .0678205232261962
1 2020  3   .00147013177931144    -.027340590509834     .0235871204418912    .0634903349864358     .0774651551436273    -.0078551695294735   -.0264430153434314   -.00757762188461279    -.0208933458869336            -.258719438      .034356427315474
1 2020  4  .000879621111912736   -.0412258409797747    -.0464239264933342   -.0354164216813956   -.00769035371363033    .00740811359677171      .03987497547989     .0585826533477167    -.0174629857934983             .173846838    -.0855478466201862
1 2020  5   -.0123343388472308   -.0354628990627381    .00460963264607088   -.0177993098080688   -.00127736723957018    .00475240310478628   .00484766391049881    -.0236173228739637    -.0361069491277507             .067755406   -.00869879571137265
1 2020  6   -.0220483597173234  -.00461170715940171     .0215865939707403   -.0134177768957222    -.0062498631293933   -.00225181120111037   -.0269812207622338    -.0157927994929213    .00108229486381146             .062396671   -.00453389694799365
1 2020  7   -.0195753804501781   -.0408340445682482     .0708583717467222   -.0034096277304223      .024880477014722    .00542392113045123    .0284321794024372   -.00543746030359969    -.0380827555188398             .049731879     .0525070414533334
1 2020  8  -.00880036518178188   -.0229768019323641    .00300897958372201   -.0483141864124786    -.0166517066735562    .00492077917914172    .0269755834434207   -.00734298257141974    -.0403836128841195             .072974017    -.0796254404964626
1 2020  9   .00942650268644734  -.00159692534220104    .00624485477604054 -.000766399691220458    .00869111318343257    .00263327818748964    .0408415830537881    .00760910703485326    -.0126113203333108            -.058954468     .0325244174979799
1 2020 10   .00901833305087965  -.00150942416670501     .0176322961664969  -.00391343833740999    .00335578425668693    .00359545632952784   -.0135883142289126   -.00453593629299935   -.00589249656010002             .002979384    -.0155436776247775
1 2020 11   .00129783413919238    .0880357068382909     -.112014820758817   -.0611762629572166    -.0920982644745734    -.0179737625284729    .0383450933465859     .0077328074923325     .0589354132768446             .149438187      -.16439540932944
1 2020 12   -.0109265181049099    -.031997379262703     .0590285424625903   .00519642490950143     .0247344002193503     -.001365600938225  -.00344483145436179     .0104779976984649    .00762702002607303              .06873572     .0240528331624842
1 2021  1  -.00327579842391743  -.00825850595839482     .0212076536882929   -.0172069062766411    -.0076782823413823    .00998408826802101   .00935732743881033   -.00907831003161402    -.0141811106614053            -.001291551   -.00952756784424498
1 2021  2   -.0140535872975289    .0306801644587285     .0251765399798342   -.0296284954952314    -.0447697278952798    .00261579595611623    .0225273697698277    -.0167103955046239     .0170094280776431             .021306603    -.0417891185224227
1 2021  3    .0254566629742626    .0321425581999553    -.0194225976910063    .0255852162056748    .00694473916064307     .0005476986639183   -.0118129623048321    .00303619661106878     .0347109159653438             .006455285    .00281708484898459
1 2021  4   -.0233155549171809   -.0380173779383543     .0179124938333405   .00444550063203739     .0156035510305476   -.00207414796849488  .000893943039535892 -.0000813067559761876    -.0309112744178841              .05033252   -.00924515609362737
1 2021  5    .0130854119685262     .014577758335329   .000781001054461022    .0279084121048644     .0170930065433733   -.00598645781720386   .00917307251196418    .00882546438313193     .0167642681963705             .023397196     .0203216194036775
1 2021  6   -.0237400303799418  -.00876728639724266     .0140623573563479    .0037186410079666     .0076462079314114   .000823701293044827   -.0265816751976696     .0140303354849868   -.00513038452210297            -.008113372   -.00586265192843061
1 2021  7  -.00509675062874337 .0000392957407438771   -.00646368001218791    .0183454164729222     .0112423984457966    .00927039108006296    .0125381113953949     .0149397856972658    .00389355306281868            -.010283559     .0368757179929463
1 2021  8    .0204091489834843  -.00628090049242011    .00605338050067811   -.0440147185839036    -.0286504507474705   -.00549029721503522  -.00841682361117835     .0195829265315815    -.0514669576520848             .022474379    -.0288842401529371
1 2021  9    .0188793898974942    .0436958834017647    -.0170055054539932   -.0500623903900294    -.0580047412311948    .00291388543694119    .0258766163071536    -.0125902804135902   -.00746925099023798            -.021729216    -.0258937722916711
1 2021 10  -.00763658660838685   -.0148375120470741    -.0116119420134778  -.00883595172813392   -.00336985434669659    .00275025001578972    .0359496559795425    -.0136285208694897    -.0220148066437734             .041551517    -.0232401657898012
1 2021 11  -.00601710029224374   -.0204459598997439   -.00671566988821435    .0340803932183872     .0329617228310361      .020613134860785   -.0134336868718089   -.00688535760223566  -.000433476711398872            -.059524591     .0166499501363539
2 2016  7    .0113301303444165  -.00463374420940109    .00762639619034287 -.000659599497032884    .00499958142408177    .00603996421769842   .00837379696871491     .0225713739640594    -.0176708986858416             .010104005   -.00788098953748584
2 2016  8  -.00178087710417655   -.0112280875700834     -.031479747573866  -.00680896500805368    -.0101497366369872    -.0185951811475601   .00793109099116222    -.0308436398806069    -.0011224601709768            -.004411858    -.0395981607091639
2 2016  9     .015560565722376   -.0200163323028276     .0110709894014763  -.00394661069295545   -.00313221386058626     .0137306383271395   .00578845959997035     .0283519435199829    .00375695908554087             .038116013    -.0253102765518138
2 2016 10    .0353693394624116   -.0170311111203626   -.00289435406199445  -.00331864249098326    -.0117683197661129     .0139464621334585   .00670537396512844    -.0128089934696528    .00380258576001153            -.073173616    .00112454281403541
2 2016 11    .0159957092699501   .00617428308914794    .00366033703335298   -.0222545635830136    -.0271434337732924    -.0109527853329981   .00889275169500577   -.00861478690172867    .00095510429748415            -.053873813    -.0620643551939633
2 2016 12   -.0092310004419941   -.0137952318207563   -.00376424047138597   .00366280561442689    .00826210478132716    .00171405364852289   .00770642086983866     .0228496591136777    .00320370127434196             .025400026     .0125045118810198
2 2017  1   -.0249782431100716 .0000531478772713855   -.00642065805079416  -.00765518709408959    .00219630488074066    .00364114806378601    .0204961417449306   -.00800700018790559    .00331438076859061             .005931999    .00340689193275543
2 2017  2  -.00963475487778513 -.000572011186172759    -.0200198614737103    .0118298050990007    .00812809958002071    .00616585055014865  -.00283771326811825    .00182410293895485    -.0142346056502978             .019842021     .0192216205482853
2 2017  3    .0113973417759172   .00305577477784535    .00792426478853006   .00100268754786684   -.00934392742908184    -.0016026155331888  -.00220201381973261   -.00879818763742871    .00782278482764899             .029045058    -.0594174978807386
2 2017  4   .00636110696269143  -.00772235693195447     .0118076114481896  -.00249358085121237   -.00780371747273963  -.000347200545467432  -.00897402550553793    -.0019728280268375   .000537005128378984             .028289718    -.0237053309179574
2 2017  5    .0527828621589939   -.0192543365629583   -.00956903245617221    .0128562545841009   -.00157412969088472    -.0175669216081075   -.0187014607841635    -.0122591083498021    .00167579050291723             .052400294     .0391309009894046
2 2017  6  -.00537580326984195    .0149208329758294    .00238477905571138    -.013460403221149    -.0103278395978685    .00229891348276803    .0258989004624805   -.00633658195076446     .0123853869828851            -.028431494     .0122017617948463
2 2017  7   .00303646695946453  -.00338698064276573    -.0195011195309759   .00240756068284178    -.0178123705373806   -.00900060082022819    -.021774265650063    .00310784509832104     .0102217922402523             .075011852    -.0493662374482658
2 2017  8  .000449298806724048   .00715733686560427     .0255420315763589 -.000604026971644321    .00197083570573442     .0013334261870797 -.000444688353957691    .00189728689011933    .00806823465724645            -.018346408   -.00165969399542466
2 2017  9   -.0176833641307197   -.0329713366935752     .0174050934414767  -.00481675967902161   -.00873687375379324   -.00873600454236507      .01523826298044    .00463052315456645   -.00908560022109394             .025201583    -.0249712763668356
2 2019  2   -.0125680449769114    .0166632179676989     -.019909810686579   -.0143588293090328     -.019335249631626    .00533264099143867   -.0184544118698227   -.00816761623590136  -.000824292822350025             .017090656     .0061945657038806
2 2019  3    .0255639010930275   .00106239562347042     .0173287615983129   .00969568805902206    .00903282402415415    -.0227758047856483   -.0112708298722907  -.000144397920771977    .00188687060067244             .022454851    -.0059490660859547
2 2019  4    .0411174656950184    .0295119673038027    -.0280168354756204  -.00390548205898843    -.0216238238336649      .010725839263115    .0142495904124288     .0200353518798993      .051128015076627             .039734158    -.0432348490729624
2 2019  5    .0355894268551625    .0249214697547572     .0716731596704038  -.00362079445389595      .030479572349386   .000879798823745409   .00305373973115031     .0293636739559729     .0153667393236109            -.062535187     .0754064316799845
2 2019  6     .026269430249957  -.00414826537730322    -.0290074175588675   -.0361680556926481    -.0598131056192068    .00727010946012654   .00858191900834705     .0039628559743354    .00820887162697598             .061334217     -.048305447390472
2 2019  7    .0154177807553073    .0130108404197426     .0101291543104415    -.019577552495524    -.0302599817116025    -.0193011199030977   -.0137051466455228    -.0447187657515438   -.00862128246649038             .039671698    -.0294982860774511
2 2019  8   -.0153684740310597   -.0088017287373964     .0237064159001213   .00219895207201545    .00904650103504457   .000797279413217833  -.00656499476128197    .00406181972325781    -.0146375478654271            -.044794766      .040298147034388
2 2019  9   -.0354497616374863   -.0115952404767217    -.0420656517195602    .0305976476842783    .00325240110291013    -.0122387030903185   -.0156211921042094    -.0251295338483037     .0318221855853385             .020389297    -.0337038789676866
2 2019 10    -.044503175821363   -.0167913725124233     -.045153970113062   -.0185784333874749      .010996498962562     .0106308338248287    .0303885908178172   -.00156195794061088    -.0110389537300509            -.036605577     .0127162123346386
2 2019 11   -.0235960415511923  -.00338106390512777   -.00825318224091324   -.0210174291864027    -.0173996328057737 -.0000426198677766782  -.00116531446564961    -.0239711294292298     -.025358229516124             .005894164     .0236077162900722
2 2019 12   -.0289759345166589   -.0184444258512122   -.00640651094247767   -.0194266997314958    -.0231294016883835    .00350890733398602 -.000375996368283183   -.00368208748255689    -.0129877975593674             .029441919    -.0223755906630415
2 2020  1   -.0257500192514364    -.020101407367253     -.034151008464862    .0294091195005445     .0427282401757227    .00752919957562149    .0114616216418746    .00439155619549574    -.0143750133812448            -.031370772     .0537957666037476
2 2020  2   -.0693079177485603   -.0449106163189235    .00419176371795531   -.0104067181899058     .0157987734093859     .0125062360408945    .0206653023616276    -.0661964493119205    -.0382575260222415            -.144170912     .0878955979344611
2 2020  3   -.0353296825131341   -.0446592365397238   -.00679956648011083   .00821745296616909     .0387267781476497     .0181874393540491   .00251650415963106    -.0332502512303097    -.0228631850624193            -.134514385      .116045090973511
2 2020  4   -.0236605867934013   -.0154822892607566     .0119012244146647   -.0099779937225756   -.00255783092423338     .0127016413344787    .0129987336242336     .0250239320763733      -.01411681752091             .045920103    -.0166814555720179
2 2020  5   -.0214035188265784   -.0421039546547803     .0521550231442597   -.0204739797919246     .0214895073200411    .00399926456025332   -.0122270374031354    -.0205737498598456    -.0729758471247604             .034017066     .0515261034865272
2 2020  6   -.0212484421526358    .0097295414141397   -.00879122294192702 -.000709430951915465  -.000498495066716156    -.0134587693607626   .00101110805707687    -.0351795438712944   -.00223972712427467             .038313422    -.0671640543785925
2 2020  7   -.0500937026013695  -.00217615561165716       .03084838942467     .014274847422831     .0172296841113485   -.00101879364695386  -.00997469773469359    -.0112365100224348    -.0141821658523546              .04425591     .0182462846593073
2 2020  8    .0125984983222223    .0212614349450418    -.0464563808789422  -.00708725853454274    -.0094080184486825    -.0151415903243109    .0112622258508833     .0212144489561929     .0400244042544903             .040084543    -.0273041602821023
2 2020  9    .0231923601263246   .00125676115325481     .0202941036048591   -.0208478274757722     .0245937261127102   -.00434374564735639     .023176345827319     .0138248012163024    -.0223846495209377            -.038579268     .0708594454288684
2 2020 10    .0292194056452829    .0147747828285067    -.0281326499170174    .0103788958702436    .00366589360232981    .00922970082965455  -.00420300177656164     .0177830327683153     .0294943952846829            -.057468281     .0011781306528427
2 2020 11    .0954700122332708    .0810994563575246     -.134655331577762   -.0427745093023659    -.0987891699420465    -.0244457604822838   -.0094424200663312    -.0108839126550072     .0604380689803196             .209006326     -.184339212401045
2 2020 12    .0241910340591527    .0166920352404467   -.00385188739263715   -.0160546180974567   -.00352734649516864    .00408009261988146     .005246706203302   -.00615106211218655     .0079996624684365             .035630874    -.0142925010539042
2 2021  1   -.0107277105710012    -.052978050871033   -.00790994436223597    .0329117213647601     .0323198024153898    .00157792980116368    .0103938108704524    -.0215762305346502    -.0268023513169021            -.021601137     .0508283078604845
2 2021  2    .0321103611107229     .024685671226695     .0193906035332339    -.036399235213786    -.0120127802012853   -.00119370384954764    .0278937532054591    .00886872796545414   -.00818901086363949            -.000783545    .00857440009929769
2 2021  3    .0194540477688538    .0549853103009261    -.0314947439102355     .023196547332905    -.0183597161002695    .00285775975108482    .0225314050383975     .0576988085351992      .083798585232103             .026042106    -.0723490434055713
2 2021  4   -.0109991709252692  -.00102134382723649    .00654149581419047  -.00389344660281794   -.00181648265591277   .000968767381542593  -.00415601487487534    -.0225591138041771    -.0181585381922903             .058010294    -.0415485424814639
2 2021  5  -.00236572009670289    .0364300924238788     .0239561722080647   .00719700088183608    -.0100690452268674    .00727561649941458   -.0124128840616875    -.0116925592255407     .0162951677185475             .049778201    -.0327220707637087
2 2021  6  -.00193199908808735    -.056005847700428    -.0482307288838797  -.00433333080401692      .016818068904829     .0114132520929337   -.0130839902496802     .0370677102206099    -.0669416534214579            -.027972698     .0385032633557766
3 2011 10   -.0803935003808703   .00329124896415153    -.0678534046043452    -.030648247460683    -.0372810576944524     .0311233360459423  -.00307325823324042     .0574620474947509     .0147168980101241             .184211636    -.0634073692249811
3 2011 11    .0113349499083564    .0179127369045561       .04293277880284    .0387297350178403     .0444114843443834    -.0072879936726022   -.0108674041595758     .0146259688885197      .012216044796825            -.069958936     .0631091992948572
3 2011 12    .0314079861569432    .0139701315147082    .00999728305545283   .00431337241529653    .00440349143448589   .000970840216260511   -.0015534926357969   -.00698883545152544     .0111248005659045            -.021381665     .0691683926256697
3 2012  1   -.0525534498937687   -.0401111422358408    -.0534217872869971  -.00458228166003573    -.0213523739290364    -.0214837440476619   -.0173401732553516     .0455174115694431    .00643040058601516             .147686751     -.137790336311302
3 2012  2    .0156808073845719   -.0181863191882262      .009723646148191  -.00101473271416493     .0149251554526067     .0026131008650004   -.0117805724817498     .0100716239561298    -.0184944330447141             .090721518     .0152620298228838
3 2012  3    .0126362762853531    .0117078128586391       .02366517178612    .0232531536407939     .0278478244571162   -.00368824394171529    .0197916878614127    -.0177654044182968   -.00145504168309773            -.047068747     .0502497220737812
3 2012  4   .00215854955712327    .0196609823709806     .0302062418151105    .0257597731193667     .0486027411399389    -.0111074378576153 -.000992899589079309    -.0155064228855737   -.00850550724920501            -.045572486      .077080111604536
3 2012  5  -.00670065186769101    .0223095759975199     .0406902474377288    .0406877872446778     .0563874683811549   -.00863961145415089  .000901608761024428    -.0299689414986499   -.00774072238712174            -.142927239      .109547903832033
3 2012  6   -.0085181914228094    .0582422818968926     .0906942185781567    .0403934599716479      .064460300260052      .014451035948257   -.0107644721986902    -.0113150675529617      .031253787269354             .005821878      .088225949714227
3 2012  7   -.0102376976379644   -.0131871592407672       .02716376670422   -.0021257210422582    -.0104939048333297      .018653653719708    .0103145526978594     .0167842351100645    .00812181485363104             .012035391    -.0391391934582643
3 2012  8   -.0193694759536035   -.0165400727128509    -.0455140264229837    -.041464388994307     -.033962905598671    .00458414675973482     .028924357870643   -.00429734647009337    .00329645510498139             .032281552    -.0550085009598844
3 2012  9   -.0150657065532342    .0167691693226354    -.0139042124548172   -.0201180501982077    -.0245667920398892    .00172764977119952 -.000187794331709795   -.00859513797879342     .0184103310481563             .035970731    -.0457046935335133
3 2012 10   .00357178300292217    .0168045710616045     .0480063285106422   .00840088066149913     .0245772935909004   -.00159078111608809  -.00162542243520945   -.00786946696938005     .0014937503668483            -.008205775      .064177818913341
3 2012 11   -.0184335858625224   .00553242284342465      .027153233650629    .0202854325481303     .0409941240668395    .00514212227076893   -.0158861306570509    .00565265987348573    -.0170274843604258            -.021774332     .0353474542791334
3 2012 12    .0242070540468611  -.00646789233132137     .0019757048020681   -.0199597635588768    -.0263702662560062    -.0168643383430835  -.00981307434965963   .000779737959800322     .0107908072227465             .079033034    -.0437289104901003
3 2013  1    .0244064303735581    .0407293009679382     .0129859402411091   -.0175281485610451    -.0027728925656566  -.000966297766865993   -.0018631683986121     .0112172873881741     .0208360783370859             .038416158     .0112332550999411
3 2013  2   -.0316444078787876   .00269897677135394     .0207933126467987    .0156158347450578     .0222645309342416    -.0102921391427939   .00519501938369044   -.00779203458410698    .00940848924337586             .010881336      .044847895944362
3 2013  3   -.0165153804771923    .0123969784575241     .0325007823106221    .0230486292676657     .0201758391973795   .000766271167263099  -.00395042266273161   -.00473281646794982     .0184450682660948            -.024152854     .0347633464231942
3 2013  4   -.0210077157097835   -.0149698418464625    .00932793299192547    .0247496551913774     .0436041122572965    .00390933027230879   -.0219525489365572     .0173516534480735   -.00372212791545241            -.004030647      .080611654378334
3 2013  5  -.00138159363403128    .0163585411408407     .0209908305155756   .00500299645751991     .0132149348765664   .000558459887366172  -.00476732186271116   -.00530690455742854    -.0111382018064492            -.050344521     .0118378077959061
3 2013  6   .00636459427871938     .010701454804171     .0249130030374594    .0244769741662479     .0224324467912566  .0000284403486834524   -.0150282738077587    .00209546299581399    .00133589032401832             -.10918477     .0216347872533874
end
[/CODE]