Announcement

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

  • How to resolve xtine _ 'too few variables specified' error

    I have a data with more than 1million rows, and I have no issues with running xtset command, but I have having this error with xtline _ 'too few variables specified'. Can someone please help me with this?

  • #2
    The syntax for xtline is

    Syntax

    Graph by panel

    xtline varlist [if] [in] [, panel_options]


    Overlaid panels

    xtline varname [if] [in], overlay [overlaid_options]
    So you need to specify a variable if overlaying plots or one or more variables if graphing by panel. In a sense, what do you want to plot?

    Comment


    • #3
      The below mentioned is my code:

      xtset school1 school_year
      xtline drugandalcoholuse_mean, tlabel

      The results of xtset are
      (
      Panel variable: school1 (weakly balanced)
      Time variable: school_year, 2008 to 2021
      Delta: 1 unit
      )

      Where as for xltine I am getting "too few variables specified" error.
      Am I missing something in this?

      Comment


      • #4
        Thankyou for the reply. The below mentioned is my code:

        xtset school1 school_year
        xtline drugandalcoholuse_mean, tlabel

        The results of xtset are
        (
        Panel variable: school1 (weakly balanced)
        Time variable: school_year, 2008 to 2021
        Delta: 1 unit
        )

        Where as for xltine I am getting "too few variables specified" error.
        Am I missing something in this?

        Comment


        • #5
          xtset school1 school_year
          xtline drugandalcoholuse_mean, tlabel
          The 1 million+ observations over a period of 14 years represent over 71,000 panels - so I do not see any scope to create such a graph. But you can start at:

          Code:
          xtset school1 school_year
          sort school1 school_year
          xtline drugandalcoholuse_mean in 1/140
          If this results in an error, provide a reproducible example, e.g., by copying and pasting the result of the following:

          Code:
          dataex school1 school_year drugandalcoholuse_mean
          Last edited by Andrew Musau; 30 Jun 2023, 18:57.

          Comment


          • #6
            Thankyou so much for the reply!

            Comment


            • #7
              I should add to #5 that you can plot the averaged drug and alcohol use in the sample. This will be across all panels.

              Code:
              preserve
              collapse drugandalcoholuse_mean, by(school_year)
              set scheme s1mono
              tw line drugandalcoholuse_mean school_year, sort xtitle("") ytitle(Mean Drug and Alcohol Use)
              restore

              Comment


              • #8
                Thank you for #7 plot. I have already plotted a similar graph. But as for 'xtset', I am getting an error. It says 'repeated time values within panel'. Can you please help me with this as well?

                Comment


                • #9
                  That is indicative of duplicate observations. To xtset, you need school-level panel data, i.e., at most one observation of a school in a given school year. Perhaps you have student-level data. In any case, once you understand the structure of your data, you can still enforce a school-level panel by collapsing the data if the aggregation is at a lower level. Whether you sum or take the mean depends on what makes the most sense to you.

                  Code:
                  collapse drugandalcoholuse_mean, by(school1 school_year)
                  xtset school1 school_year
                  or

                  Code:
                  collapse (sum) drugandalcoholuse_tot= drugandalcoholuse_mean, by(school1 school_year)
                  xtset school1 school_year

                  Comment


                  • #10
                    It worked. Thank you so much. But can I not use "xtline drugandalcoholuse_mean, overlay legend(off)"? It is giving me error of "too many sersets". What could be the possible reason?

                    Comment


                    • #11
                      What I said in #5. With overlaid lines, you are already struggling with \(N= 10\) panels. So it is not reasonable to expect that you will produce any meaningful graph with a large number of panels.

                      Comment


                      • #12
                        Got it. Thank you so much !
                        Last edited by Sri Kruthi; 04 Jul 2023, 08:26.

                        Comment

                        Working...
                        X