Announcement

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

  • Revenue Growth Trend

    Hi everyone,
    I have 15 years (2005-2019) of 548 municipalities general revenue data. I'm trying to generate the revenue volatility which is defined as the extent to which actual revenue differs from expected revenue. To measure deviations in actual revenue from expected revenue, a revenue growth trend regression model was first estimated as Rit = exp( α + β1 t + β2 i)

    In this equation, the natural log of total general revenue for municipality i in year t (Rit) is modeled as a function of a time variable indicating the year (t) and a series of n-1 dichotomous variables identifying each municipality in the data set (i). From this regression equation, absolute deviations of the residuals serve as the dependent variable of revenue volatility.
    How can I generate this revenue volitality using stata?

    Thanks in advance
    Last edited by Titik Minarti; 19 Jul 2022, 16:08.

  • #2
    You do not provide example data, so I have to make guesses about how your data might be organized--there are several possibilities that fit your description. Also I'm not sure what "absolute deviations of the residuals serve as the dependent variable of revenue volatility" means. I'm assuming you meant that the median absolute deviation from the median residual is the desired municiaplity's measure of volatility.

    The code below illustrates the approach by doctoring the Stata web-data set grunfeld.dta. If your data are not in long layout, and are not numeric variables, then this code will require substantial adaptation.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte municipality int year float revenue
    1 2005 3078.5
    1 2006 4661.7
    1 2007 5387.1
    1 2008 2792.2
    1 2009 4313.2
    1 2010 4643.9
    1 2011 4551.2
    1 2012 3244.1
    1 2013 4053.7
    1 2014 4379.3
    1 2015 4840.9
    1 2016 4900.9
    1 2017 3526.5
    1 2018 3254.7
    1 2019 3700.2
    2 2005 1362.4
    2 2006 1807.1
    2 2007 2676.3
    2 2008 1801.9
    2 2009 1957.3
    2 2010 2202.9
    2 2011 2380.5
    2 2012 2168.6
    2 2013 1985.1
    2 2014 1813.9
    2 2015 1850.2
    2 2016 2067.7
    2 2017 1796.7
    2 2018 1625.8
    2 2019   1667
    3 2005 1170.6
    3 2006 2015.8
    3 2007 2803.3
    3 2008 2039.7
    3 2009 2256.2
    3 2010 2132.2
    3 2011 1834.1
    3 2012   1588
    3 2013 1749.4
    3 2014 1687.2
    3 2015 2007.7
    3 2016 2208.3
    3 2017 1656.7
    3 2018 1604.4
    3 2019 1431.8
    4 2005  417.5
    4 2006  837.8
    4 2007  883.9
    4 2008  437.9
    4 2009  679.7
    4 2010  727.8
    4 2011  643.6
    4 2012  410.9
    4 2013  588.4
    4 2014  698.4
    4 2015  846.4
    4 2016  893.8
    4 2017    579
    4 2018  694.6
    4 2019  590.3
    5 2005  157.7
    5 2006  167.9
    5 2007  192.9
    5 2008  156.7
    5 2009  191.4
    5 2010  185.5
    5 2011  199.6
    5 2012  189.5
    5 2013  151.2
    5 2014  187.7
    5 2015  214.7
    5 2016  232.9
    5 2017    249
    5 2018  224.5
    5 2019  237.3
    6 2005    197
    6 2006  210.3
    6 2007  223.1
    6 2008  216.7
    6 2009  286.4
    6 2010    298
    6 2011  276.9
    6 2012  272.6
    6 2013  287.4
    6 2014  330.3
    6 2015  324.4
    6 2016  401.9
    6 2017  407.4
    6 2018  409.2
    6 2019  482.2
    7 2005    138
    7 2006  200.1
    7 2007  210.1
    7 2008  161.2
    7 2009  161.7
    7 2010  145.1
    7 2011  110.6
    7 2012   98.1
    7 2013  108.8
    7 2014  118.2
    end
    format %ty year
    
    
    capture program drop one_municipality
    program define one_municipality
        regress log_revenue year
        predict resid, residual
        egen wanted = mad(resid)
        exit
    end
    
    gen log_revenue = log(revenue)
    runby one_municipality, by(municipality)
    -runby- is written by Robert Picard and me, and is available from SSC. The same basic idea can be implemented without using -runby- or any other user-written command. But the use of -runby- makes the code simpler, and also much faster.

    In the future, when asking for help with code, always show example data, and do that using the -dataex- command, as I have here. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thank you so much for your answer. And I'll remember in the future to use data example when asking about code. Your data example is similar to data that I have.

      Comment

      Working...
      X