Announcement

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

  • Help: Export Excel Mulitple Tabs Based on Criteria within a group


    I am trying to create excel files to provide to a school’s principal detailing information pertinent to each group of staff within their school on each tab. Currently
    I am using the code shown below. When I use this code, I am able to get a file to output values on a tab for “Speech-Language Pathology,” although the school has observations for each category in ‘y’. However, at the same time the code is ran, I receive an error code of “too many or no observations specified.” Please help and let me know what I can do to create one file per school, with each category in ‘y’ as it’s on tab. The screenshot doesn't show it, but to confirm there is a semicolon at the end of export command, just after the word replace.

    Stata Version: SE 12.1



    Attached Files

  • #2
    It is not compulsory to follow our strong request to use full real names. Equally it is not compulsory to answer questions here.

    Comment


    • #3
      Thank you Nick. I will re-post. If you are able to assist and/or suggest steps to resolve, then please feel free to respond. If not, then no response is warranted.

      Comment


      • #4
        What are the semicolons for? Unlike SAS, they are not necessary in Stata. I don't know if they would cause the problem you are experiencing, but it's worth retrying without them.

        If you still get the error after removing the semicolons, you should probably tell us more about your data. The error you are getting is probably not a syntax error, but rather one of correctly identifying which observations in your data set are to be output to Excel.

        Comment


        • #5
          Please post with your full real name (contact the administrators to change your user name).
          Rather than pasting an image of your code, copy/paste the text and format it as code using the advanced text editor.

          The problem I see with your code is that the replace option overwrites the previously created Excel workbook (and sheet). If the code were to run without errors, you would get one file per school with one tab each (i.e. the last category in your list). So get rid of that option.

          The error you report is due to the fact that there are zero observations that meet the conditions you have established (with the if). The following reproduces the error you mention:
          Code:
          clear all
          set more off
          
          input ///
          str6 ticker str2 group year
          PETR4 BH 2000
          ABEV3 BL 2000
          USIM5 SM 2000
          PETR4 BM 2001
          ABEV3 BH 2001
          USIM5 SM 2001
          end
          
          foreach f in "one" "two" {
              foreach c in "audio" "bahavior" {
                  export excel using "`f'" if year == 19, firstrow(variables) sheet("`c'")
              }    
          }
          Once we eliminate the if condition, it works fine.
          You should:

          1. Read the FAQ carefully.

          2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

          3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

          4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

          Comment

          Working...
          X