Announcement

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

  • Can't load a file with -IMPORT EXCEL-

    I'm seeking to combine into one Excel file the results of two commands. In my complete code that follows:
    1. The first command is TEFFECTS IPWRA, which can return stored results using -ESTIMATES TABLE- and -ESTTAB-.
    2. The second is a post-estimation model fit test -TEBALANCE, OVERID-, which can return results using -RETURN LIST- and -PUTEXCEL-.

    I've been successfully able to save the first command's results using -ESTTAB-, which only saves to *.csv Excel file format.
    I've also been successful in saving the post-estimation command results using -PUTEXCEL-, which can only modify *.xlsx Excel files.

    In order to modify the Excel file to add the p-value of the second command, I need to convert from *.csv to *.xlsx, but my code below returns error "file results2.csv could not be loaded" at that step. (I've confirmed correct directory, and that the file is not open.) Any advice would be appreciated.

    Code:
    clear
    use http://www.stata-press.com/data/r15/cattaneo2
    teffects ipwra (bweight mmarried mage prenatal1 fbaby) ///
        (mbsmoke mmarried mage prenatal1 fbaby), pomeans
        estimates store model1
        estimates table
        esttab model1 using results2.csv, b(2) se(2) r2 replace
            preserve
                clear
                dir
                import excel using results2.csv
                export excel using results2.xlsx, replace
            restore
    tebalance overid
        return list
        export excel
        putexcel set results2, modify
        putexcel B12=`r(p)'

  • #2
    results2.csv is not an Excel file, so -import excel- can't read it. It's a .csv file (which is a comma delimited text file), and to read it you need to use -import delimited-.

    Comment


    • #3
      Thank you Clyde!
      -import delimited- can read the file just fine. I've studied the -help- file for -import delimited-, -import excel- and -export excel-, and don't see a way to avoid having each cell preceded by "=. Is there a workaround for this?

      Comment


      • #4
        and don't see a way to avoid having each cell preceded by "=.
        I don't know what you mean by this. Can you show some examples of what is happening?

        Comment

        Working...
        X