Announcement

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

  • Create program with string argument (name of file to be created)

    After running some regressions followed by postestimation commands, I would like to export some store results to excel using the -putexcel- command. I am doing this for different specifications.

    Take the simple example below.

    Code:
    ssc install weakivtest
    sysuse auto, clear
    
    ivreg2 price (weight=length foreign) i.turn, cluster(turn) small
    weakivtest
    
    putexcel set "ESTIMATION1", modify
    putexcel B1 = "ESTIMATION1"
    putexcel A2 = "KP F-stat"
    putexcel B2 = (e(rkf))
    putexcel A3 = "Effective F-stat"
    putexcel B3 = (r(F_eff))
    
    
    ivreg2 price (weight=gear_ratio foreign) i.turn, cluster(turn) small
    weakivtest
    
    putexcel set "ESTIMATION2", modify
    putexcel B1 = "ESTIMATION2"
    putexcel A2 = "KP F-stat"
    putexcel B2 = (e(rkf))
    putexcel A3 = "Effective F-stat"
    putexcel B3 = (r(F_eff))
    The only thing that changes in the -putexcel- commands after the estimations is the name of file (which is also the name of one of the columns): ESTIMATION1, ESTIMATION2, ....

    I would like to write a program with such name (eg "ESTIMATION1") as an argument. I would then call this program after each estimation with the name of the file to be saved. Would anyone be able to help? Thank you.
    Last edited by Paula de Souza Leao Spinola; 09 Feb 2023, 10:26.

  • #2
    Here's a minimalist version (no error checking, etc.) to accomplish your end.
    Code:
    cap prog drop putprog
    prog putprog
    syntax, outfile(string)
       putexcel set `"`outfile'"', modify
       putexcel B1 = `"`outfile'"'
       putexcel A2 = "KP F-stat"
       putexcel B2 = (e(rkf))
       putexcel A3 = "Effective F-stat"
       putexcel B3 = (r(F_eff))
    end
    //
    ssc install weakivtest
    sysuse auto, clear
    ivreg2 price (weight=length foreign) i.turn, cluster(turn) small
    putprog, outfile("estimation1.xlsx")
    I'd note, by the way, that r(F_eff) isn't in the return list of your estimation command.

    Comment

    Working...
    X