Announcement

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

  • How to accelerate svar

    Hello,
    I am trying to estimate structured vector auto-regression (-svar), with Chelosky decomposition. What bothers me now, is that it takes ages to process the data with -svar-. I would love to ask for any recommendation to improve the efficiency of the data processing.
    Code:
     program my_irf2
        local gid = id[1]
        gen mydate =_n
        xtset id mydate
        matrix A1 = (1,0,0 \ .,1,0 \ .,.,1)
        matrix B1 = (.,0,0 \ 0,.,0 \ 0,0,.)
        svar vwretd sdvol RET, lags(1/5) aeq(A1) beq(B1)
        irf create order1, set(var2, replace) step(15)
        gen response_rm_0 = e(A)[3,1] *-1
        gen response_x_0 = e(A)[3,2] *-1
        keep id response_rm_0 response_x_0
        duplicates drop id, force
    end
    
    forval y = 1960/2015{
        use `y'_scaled.dta, clear
        keep PERMNO date RET vwretd size sdvol year id
        runby my_irf2, by(id)
        save `y'_irf2.dta, replace
    }
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double PERMNO long date double(RET vwretd) float(size sdvol year id)
    10006 5845  -.006493506487458944             .008231689   218.025    -95625 1976 34211
    10006 5848                     0              .01806659   218.025         0 1976 34211
    10006 5849    .08496732264757156              .01221413    236.55    377650 1976 34211
    10006 5850 -.0060240961611270905    .005371325000000001   235.125   -330000 1976 34211
    10006 5851     .0181818176060915    .006731177000000001     239.4    117600 1976 34211
    10006 5852   .008928571827709675             .004472628  241.5375  207637.5 1976 34211
    10006 5855    .02654867246747017    .013304120000000001    247.95    369750 1976 34211
    10006 5856                     0            -.006916028    247.95         0 1976 34211
    10006 5857  .0028735632076859474              .01605946  248.6625    174500 1976 34211
    10006 5858   .005730659235268831  -.0038988580000000007  250.0875  223762.5 1976 34211
    10006 5859 -.0028490028344094753             .004578305   249.375   -428750 1976 34211
    10006 5862   -.02857142873108387              .01220731    242.25   -178500 1976 34211
    10006 5863     .0058823530562222             .004928043   243.675    705375 1976 34211
    10006 5864  -.023391813039779663            -.004606988   237.975   -651300 1976 34211
    10006 5865   .005988024175167084  -.0017014649999999999     239.4    113400 1976 34211
    10006 5866     .0416666679084301              .01174169   249.375    503125 1976 34211
    10006 5869    .02857142873108387             .004386288     256.5    976500 1976 34211
    10006 5870    .03888889029622078   -.004936286000000001   266.475    949025 1976 34211
    10006 5871  -.013368983753025532            -.004476277  262.9125 -558112.5 1976 34211
    10006 5872    .01084010861814022              .01640626  265.7625  377662.5 1976 34211
    10006 5873                     0    .007567194000000001  265.7625         0 1976 34211
    10006 5876    -.0160857904702425             .001673299  261.4875   -834925 1976 34211
    10006 5877     .0272479560226202             .004400879  268.6125    640900 1976 34211
    10006 5878  -.007957560010254383    .008833184000000001   266.475   -219725 1976 34211
    10006 5879  -.026737967506051064             -.01254077    259.35   -486850 1976 34211
    10006 5880  -.016483517363667488   -.008229951000000001   255.075   -948700 1976 34211
    10006 5883   .011173184029757977             .002809287   257.925    475125 1976 34211
    10006 5884                     0             .007869854   257.925         0 1976 34211
    10006 5885     .0220994483679533             .004568761   263.625    370000 1976 34211
    10006 5886   .037837836891412735  -.0034362930000000004     273.6    643200 1976 34211
    10006 5887             -.0078125  -.0039011340000000005  271.4625   -990600 1976 34211
    10006 5891    .01312335953116417            -.004780653   275.025    236425 1976 34211
    10006 5892  -.005181347019970417             .007819952     273.6   -297600 1976 34211
    10006 5893  .0052083334885537624              .01614954   275.025    260550 1976 34211
    10006 5894    .02590673603117466             .006970134    282.15    504900 1976 34211
    10006 5897  -.014646464958786964            -.002790629  274.3125   -721875 1976 34211
    10006 5898   .010389610193669796    .004899397000000001  277.1625   2839700 1976 34211
    10006 5899   -.01799485832452774  -.0016441300000000002   272.175   -315150 1976 34211
    10006 5900  -.007853402756154537             -.01432952  270.0375   -132650 1976 34211
    10006 5901  .0052770450711250305   -.006408030000000001  271.4625  509587.5 1976 34211
    10006 5904   .010498687624931335             .003109484  274.3125    202125 1976 34211
    10006 5905  -.002597402548417449   .0057991250000000005     273.6    -76800 1976 34211
    10006 5906    .01822916604578495   -.005391966000000001  278.5875    400775 1976 34211
    10006 5907                     0            -.009327616  278.5875         0 1976 34211
    10006 5908  .0025575447361916304             .001517721     279.3    284200 1976 34211
    10006 5911   .020408162847161293              .01013001       285    810000 1976 34211
    10006 5912   .017500000074505806   .0026605450000000003  289.9875    651200 1976 34211
    10006 5913  -.012285011820495129             .003824038   286.425   -296475 1976 34211
    10006 5914  -.012437811121344566             .008563153  282.8625   -327525 1976 34211
    10006 5915  -.007556675001978874            -.008520702   280.725   -241325 1976 34211
    10006 5918  -.030456852167844772             -.01099493   272.175   -415425 1976 34211
    10006 5919  -.007853402756154537             .009886018  270.0375   -189500 1976 34211
    10006 5920    .01583113521337509           .00002507353  274.3125    173250 1976 34211
    10006 5921  -.007792207878082991            -.003901867   272.175    -71625 1976 34211
    10006 5922   .013089004904031754             .001095571  275.7375    164475 1976 34211
    10006 5925  -.010335917584598064   .0008650320000000001  272.8875   -134050 1976 34211
    10006 5926  -.007832897827029228              .01303327    270.75    -80750 1976 34211
    10006 5927   .028947368264198303    .010395970000000001  278.5875    205275 1976 34211
    10006 5928                     0            -.005262262  278.5875         0 1976 34211
    10006 5929  .0025575447361916304   .0010863700000000001     279.3    102900 1976 34211
    10006 5932  -.005102040711790323            -.003916132   277.875    -87750 1976 34211
    10006 5933                     0            -.004011204   277.875         0 1976 34211
    10006 5934   .012820512987673283    .006345531000000001  281.4375    345625 1976 34211
    10006 5935   .025316456332802773            -.004034468  288.5625    455625 1976 34211
    10006 5936  .0024691359139978886            .0003510866   289.275     35525 1976 34211
    10006 5939                     0              .01170649   289.275         0 1976 34211
    10006 5940   .017241379246115685           -.0005859863  294.2625    433650 1976 34211
    10006 5941  -.021791767328977585             -.01148907    287.85   -636300 1976 34211
    10006 5942  -.017326733097434044            -.009503256  282.8625 -689787.5 1976 34211
    10006 5943                     0             -.01012046  282.8625         0 1976 34211
    10006 5946  -.002518891589716077  -.0017659330000000001    282.15   -237600 1976 34211
    10006 5947   .007575757801532745   .0065798079999999995  284.2875     69825 1976 34211
    10006 5948    .00501253129914403            -.005900771  285.7125     70175 1976 34211
    10006 5949                     0             .003559686 289.87286         0 1976 34211
    10006 5953  .0024937656708061695             .006928967 290.59576     85425 1976 34211
    10006 5954   .017412934452295303              .01472894 295.65588  219837.5 1976 34211
    10006 5955   .004889975767582655             .003874344 297.10162    174675 1976 34211
    10006 5956   -.01946472004055977  -.0019829260000000003 291.31863 -317362.5 1976 34211
    10006 5957  -.002481389557942748  -.0062642290000000005 290.59576   -432150 1976 34211
    10006 5960  -.017412934452295303   .0009596320000000001  285.5356   -217250 1976 34211
    10006 5961  -.010126582346856594  -.0049373740000000005 282.64413   -684250 1976 34211
    10006 5962   .005115089472383261             .001835443 284.08987  221062.5 1976 34211
    10006 5963                     0           -.0001632027 284.08987         0 1976 34211
    10006 5964    .01781170442700386  -.0037462500000000004    289.15     70000 1976 34211
    10006 5967 -.0024999999441206455            -.008068697 288.42712   -219450 1976 34211
    10006 5968                     0             .005721005 288.42712         0 1976 34211
    10006 5969  -.002506265649572015             -.00409789 287.70425    -49750 1976 34211
    10006 5970 -.0025125627871602774   .0030966450000000003 286.98138  -84362.5 1976 34211
    10006 5971   .002518891589716077    .007624582000000001 287.70425    194025 1976 34211
    10006 5974    .01256281416863203              .01235602 291.31863    231725 1976 34211
    10006 5975  -.007444168906658888             -.00040424    289.15   -660000 1976 34211
    10006 5976 -.0024999999441206455            -.001331815 288.42712    -89775 1976 34211
    10006 5977    .01002506259828806            -.005132389 291.31863    322400 1976 34211
    10006 5978  -.012406948022544384   -.007415565000000001 287.70425   -258700 1976 34211
    10006 5981  -.007537688594311476  -.0027651280000000004  285.5356  -83937.5 1976 34211
    10006 5982  .0025316455867141485             .001333013  286.2585     39600 1976 34211
    10006 5983   .005050505045801401 -.00015949910000000002 287.70425    184075 1976 34211
    10006 5984   .007537688594311476             .006351148 289.87286  576437.5 1976 34211
    10006 5985 -.0024937656708061695            -.005253565    289.15   -150000 1976 34211
    10006 5988  -.012000000104308128             -.01627747 281.92126   -628875 1976 34211
    end
    format %td date
    I need to run the -runby- for 55 years. But now, just one year data can take around 2 hour to process. It is not ideal and I would love to ask for any advice. Thanks!
    Last edited by Wen-Hung Hsu; 25 Nov 2022, 13:13.
Working...
X