Announcement

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

  • "Not sorted" error in panel data

    Hi,

    I have problem with using generate command with by option in panel data.

    My code looks like this:

    xtset id reportyear
    gen nfi = a - b
    gen dnv = nfi + c + d +e
    bysort somevariable reportyear: gen nvai = (dnv - L.dnv) / L.dnv

    When I execute the do file it returns error: Not sorted?

    Can someone explain what is the problem? I think stata is confused because I am working in panel and want to make growth rate by non-id variable?



  • #2
    There is a clash between your different commands.

    Given your xtset, time series operators such as L. can only be used relative to a sort order of id reportyear, so your specification of a different sort order makes no sense to Stata.

    By the way, Stata's point of view is that you are confused.

    What sense would it make to compute growth rates in groups defined by (if I can believe what you type) somevariable? Perhaps you just want to compare growth rates under different conditions, but to do that you must calculate the growth rates first.

    (By the way, reporting literal code can never be worse and is often better than a paraphrase.)

    Comment


    • #3
      I will try to explain what is my goal. I have a panel of firms. I want to estimate the relationship between investment and, say, debt. But I would like to control for profitability of the industry. "Some-variable" , than, is dummy (string) variable for industry. So if a firm operates in the industry that has high growth rate of profit, it would have higher investment needs.

      That's way I wanted to calculate growth rate for the industry (some variable).

      Comment


      • #4
        The growth rate is just

        Code:
         
        xtset id reportyear 
        gen nfi = a - b
        gen dnv = nfi + c + d +e
        gen nvai = (dnv - L.dnv) / L.dnv
        Analysis comes after that.

        Comment


        • #5
          But that would give me growth rate if nvai for every firm through time. I understand that part. But I can't control for industry effects than. Or maybe I can just add industry dummies, not sure...

          Comment


          • #6
            Either that's the analysis, or you've lost me.

            Comment


            • #7
              Well, I thought that b< inserting industry dummies I can control for industry in general. For example everything else equal, some industry invest more than others. But if I calculate the growth rate of profit for industry by year, I can control for growth rate of value added for industry and not for industry in general.

              Maybe the soeplution is to generate this numbers sarately and then merge them with existing data set.

              Comment


              • #8
                Mislav:
                as far as controlling for industry is concerned, you can create a dummy via-fvvarlist- and plug it in as a predictor in the right-hand side of your equation.
                You also mentioned that some of your predictors are in -string- format; in general, in order to avoid the risk of intimidating errror messages , it is better that every variable of the regression model is in numeric format.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment

                Working...
                X