GithubHelp home page GithubHelp logo

Comments (4)

mcaceresb avatar mcaceresb commented on June 24, 2024

@oerdem19 This is not something that is within the purview of gtools. There are existing Stata tools to do this for various formats; if you have a specific use case I might be able to provide some guidance but I wouldn't add it to gtools directly.

from stata-gtools.

oerdem19 avatar oerdem19 commented on June 24, 2024

Thank you.

from stata-gtools.

mcaceresb avatar mcaceresb commented on June 24, 2024

@oerdem19 I didn't realize this was somewhat cumbersome; I don't use gstats like this but I figured I might as well code something to help. Please upgrade to the latest version 1.10.2 in the develop branch.

capture program drop _gstats_excel
program _gstats_excel
    syntax namelist(min=1 max=1) using/, [sheet(str) replace]
    if "`sheet'" == "" local sheet `namelist'
    mata _gstats_excel(`namelist', `"`using'"', `"`sheet'"', "`replace'" != "")
    * mata xlUsing = `"`using'"'
    * mata xlSheet = `"`sheet'"'
end

cap mata mata drop _gstats_excel()
mata
void function _gstats_excel(
    class GtoolsResults scalar GstatsOutput,
    string scalar xlUsing,
    string scalar xlSheet,
    real scalar replace)
{
    class xl scalar xlWb
    string vector xlSheets

    xlWb = xl()
    if ( fileexists(xlUsing) ) {
        xlWb.load_book(xlUsing)
        xlSheets = xlWb.get_sheets()
        if ( any(xlSheet :== xlSheets) & replace ) {
            xlWb.clear_sheet(xlSheet)
        }
        else if ( any(xlSheet :== xlSheets) ) {
            errprintf("'%s' already in workbook '%s' with no replace\n", xlSheet, xlUsing)
            _error(198)
        }
        else {
            xlWb.add_sheet(xlSheet)
        }
    }
    else {
        xlWb.create_book(xlUsing, xlSheet)
        xlSheets = xlWb.get_sheets()
    }

    xlWb.set_sheet(xlSheet)
    xlWb.put_string(1, 1, GstatsOutput.formatOutput())
    xlWb.close_book()
}
end

sysuse auto, clear
gstats tab price mpg, by(foreign rep78) mata
* mata GstatsOutput.formatOutput()
_gstats_excel GstatsOutput using gtools-excel.xlsx, replace

from stata-gtools.

oerdem19 avatar oerdem19 commented on June 24, 2024

Thank you very much. I think this can help many others too. Your program is very efficient and fast.

from stata-gtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.