Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • looping regressions with different interaction terms each time

    Dear all,

    I am still a Stata novice and first post on statalist, I have tried to follow all rules, but please bear with me if I got something wrong...:-)

    I am working with Stata 15, panel data from 1978q1-2018q4, roughly 28 countries (exporter importer). In total I have 57 variables and 51'070 observations.
    Here's an example (let me know if you need more observations):

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str48 rep str52 par double time float(value size) double(distwces trade) float(pta d_06Q2 d_06Q3 d_06Q4)
    "Australia" "Australia" 72 28904  810.2834 153.6287041996413 16.157827377319336 0 0 0 0
    "Australia" "Australia" 73 30531  952.7471 153.6287041996413 17.640132904052734 0 0 0 0
    "Australia" "Australia" 74 31271 1029.6853 153.6287041996413 19.406879425048828 0 0 0 0
    "Australia" "Australia" 75 32285 1305.2325 153.6287041996413 21.723352432250977 0 0 0 0
    "Australia" "Australia" 76 32135 1058.9723 153.6287041996413 17.654644012451172 0 0 0 0
    "Australia" "Australia" 77 34434 1156.8878 153.6287041996413 17.286184310913086 0 0 0 0
    "Australia" "Australia" 78 36111  1271.788 153.6287041996413 18.928865432739258 0 0 0 0
    "Australia" "Australia" 79 36711 1612.3412 153.6287041996413 20.033628463745117 0 0 0 0
    "Australia" "Australia" 80 37061 1228.2126 153.6287041996413 14.342584609985352 0 0 0 0
    "Australia" "Australia" 81 41885 1565.6206 153.6287041996413 18.730674743652344 0 0 0 0
    end
    format %tq time
    The dummies are equal to unity after the year specified in the name e.g. d_06Q3 = 1 if time>tq(2006q3)

    What I want to do is to run several ppml regressions as below, but each time with different dummies as the interaction term (so that in the regression below d_06Q2 is replaced by d_06Q3 in the next regression etc.) :

    Code:
     ppmlhdfe value c.size##d_06Q2 c.distwces##d_06Q2 c.trade##d_06Q2 pta##d_06Q2, absorb(imp#time exp#time imp#exp);
    What I am interested in is the pseudo-likelihood result of the in total 17 regressions.

    As I have 17 dummies and 40 variables, it is quite tedious to go and adjust each interaction term, which is why I tried using the following as a loop (for the purpose of this question i limited the list to d_06Q2-d_06Q4, in the end it will be d_06Q2-d_10Q2):

    Code:
    foreach var in d_06Q2-d_06Q4 {
    ppmlhdfe value c.size##`var' c.distwces##`var' c.trade##`var' pta##`var' c.lend_diff##`var' c.dep_diff##`var' c.monmar_diff##`var' no_cuc##`var' pre_peg##`var' pre_band##`var' de_facto_peg##`var' pre_cpeg##`var' pre_cband##`var' defacto_cpeg##`var' defacto_cband##`var' pre_cband_2pc##`var' defacto_cband_5pc##`var' mov_band_2pc##`var' defacto_mov_band##`var' free_float##`var' free_fall##`var' dual_market##`var' contig##`var' comlang_off##`var' comlang_ethno##`var' colony##`var' comcol##`var' curcol##`var' col45##`var' smctry##`var', absorb(imp#time exp#time imp#exp)
    }
    What I thought I would get was one "table" of output with the pseudo-likelihood for each regression. Instead I get one, where all dummies as interaction terms are listed, and one pseudo-likelihood:

    Click image for larger version

Name:	Screenshot 2019-12-14 at 17.20.59.png
Views:	2
Size:	54.8 KB
ID:	1528647


    Now to my question...first of all, perhaps to understand the foreach command better - why does it do this? Secondly, (and more importantly) what can I do instead to get the individual regression results without running them all separately?

    Thank you in advance for your patience and any replies!
Working...
X