Announcement

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

  • Tab2xl Loop

    Nice day!

    I have been trying to run multiple tab2xl loops using Stata. The following are 3 examples of my commands.

    local jobseeking_method "jobseeking_method1 jobseeking_method2 jobseeking_method3 jobseeking_method4 jobseeking_method5 jobseeking_method6 jobseeking_method7"
    foreach var in `jobseeking_method' {
    tab2xl `var' if survey_string == "2f" & jobseeking == 1 using Section4_LFPeveryone_Tab.xls, row(1) col(1) sheet("`var'")
    }

    local jobapplication_tab "application_nature1 application_letter1 application_affletter1 application_letterhelpful1 application_success1 application_nature2 application_letter2 application_affletter2 application_letterhelpful2 application_success2 application_nature3 application_letter3 application_affletter3 application_letterhelpful3 application_success3 application_nature4 application_letter4 application_affletter4 application_letterhelpful4 application_success4 application_nature5 application_letter5 application_affletter5 application_letterhelpful15 application_success5"
    foreach var in `jobapplication_tab' {
    tab2xl `var' if survey_string == "3f" using Section4_Jobapplication_Tab.xls, row(1) col(1) sheet("`var'")
    }

    local jobapplicationsuccess_tab "appliedjob_startyear1 appliedjob_endyear1 appliedjob_startyear2 appliedjob_endyear2 appliedjob_startyear3 appliedjob_endyear3 appliedjob_startyear4 appliedjob_endyear4 appliedjob_startyear5 appliedjob_endyear5"
    foreach var in `jobapplicationsuccess_tab' {
    tab2xl `var' if survey_string == "3f" using Section4_Jobapplication_Tab, row(1) col(1) sheet("Success - `var'")
    }

    At first, when I ran the first loop, it worked. The Excel file Section4_LFPeveryone_Tab was saved multiple times.

    However, when I tried to run the other loops, an error occurred, as follows:
    Excel file open
    Type putexcel save to save the existing open file.
    Type putexcel describe to see current settings.


    Then, I tried to re-run the 1st loop (jobseeking_method). The same error occurred.

    Could anyone please tell me what's happening here? Why did it work before but not now?

    Millions of thanks if someone could tell me how to run the Tab2xl loops successfully and consistently!


  • #2
    I have tried to re-run the Tab2xl loops today, but in vain. I haven't opened any excel files while I was running the loops.

    Could anyone please help?

    Many thanks in advance!

    Comment


    • #3
      Hello, I am new to posting to the Statalist. I am also new to using tab2xl and am getting the same error that Cindy is getting. Has any solution been offered elsewhere? Thank you!

      Comment


      • #4
        Update: I can't really tell you what I'm now doing differently, but all these produced lovely excel files:

        forvalues y=2018(1)2023 {
        tab2xl industry76 if (industry76_tm12 == 10 & year ==`y') using "$folder/indchgmatrix_LH.xlsx" [w=wgtern], sheet(`y') row(1) col(1)
        }

        tab2xl industry76 year if (industry76_tm12 == 10) using "$folder/indchgmatrix_byyear.xlsx" , row(1) col(1) perc replace

        tab2xl industry76 industry76_tm12 using "$folder/indchgmatrix_crosstab.xlsx" , row(1) col(1) perc replace

        Comment

        Working...
        X