Announcement

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

  • Using putexcel with a loop to run basic frequencies - "operator invalid" error

    Hello! I'm using Stata 13.1, and am running a basic frequency count for many variables, so am creating a loop. I'd also like to export to Excel and am using putexcel. My code (below) seemed to work with the exception I've encountered an error message related to my use of the operator Freq. Is there a different operator I should be using to describe frequency or number of observations that meet my criteria? (I haven't included an example from my dataset because I'm not sure that it's relevant but I certainly can if helpful.) Many thanks in advance!


    local row = 1

    foreach x in CG_challenge_work CG_challenge_findjob {
    tab `x' if CG_child_zero_four==1
    putexcel A`row'=("`x'") B`row'=(Freq.) using results.xlsx,
    modify keepcellformat sheet ("results")
    local row = `row' + 1
    }

  • #2
    Figured it out! I had to run a return list in order to identify the scalers which told me that I needed to write r(N) instead of Freq.

    Final code was as follows, in case anyone else encounters a similar challenge:


    local row = 1

    foreach x in CG_challenge_work CG_challenge_findjob {
    tab `x' if CG_child_zero_four==1
    putexcel A`row'=("`x'") B`row'=(r(N)) using results.xlsx, modify keepcellformat sheet ("results1")
    local row = `row' + 1
    }

    Comment

    Working...
    X