Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Making a table for percentage changes in stata


From   "Eric A. Booth" <[email protected]>
To   [email protected]
Subject   Re: st: Making a table for percentage changes in stata
Date   Fri, 28 Aug 2009 14:15:28 -0500

Dana:

There is probably a way to get -tabout- (or possibly -tabform-) to create the % differences by group that you are looking for; however, without seeing an example of what your data look like, I'm not sure how to tackle this.

The way you describe your data in your most recent email is a bit different--now, it sounds like you want AT LEAST a 3-way table of % pre/post change. It might be easier to use -tab3way- to generate your table and then just highlight the table and right-click to copy the table in a format that can be easily pasted into excel.


Using auto.dta & renaming/recoding these variables with the names you mention (AFTER, sex, age, var), here's a quick example:


*********************
clear all
ssc install tab3way

webuse auto

rename rep78 age
rename foreign var
rename mpg sex
recode sex (12/25 = 0) (25/.=1)
     gen AFTER = 1 if price<8000
     recode AFTER (.=0)
	label def a 1 "post-", modify
	label def a 0 "pre-", modify
	label val AFTER a
	
tab3way AFTER age sex, rowpct rowtot coltot allpct

// OR maybe you want something more like: //

forvalues n=1/2 {
tab3way var age sex if AFTER==`n', rowtot coltot scoltot allpct
}
***********************

You should probably check out the tutorial created by Ian Watson (- tabout- 's author) about how to implement similar 3 way tables using - tabout- , especially when taking advantage of it's latex capabilities.
You might find the table on page 15 of this .pdf particularly helpful:

http://www.ianwatson.com.au/stata/tabout_tutorial.pdf


Good luck,

Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754




On Aug 28, 2009, at 1:35 PM, Dana Chandler wrote:

Eric,

Thanks for your response. Something very much like what you are
describing is what I currently do. It just gets annoying because if
you want to slice the data and show those percent differences for
different groups, you have to then create different "base" and "end"
values for each group. It'd be nice if somehow there was the same
flexibility you have and could just write something like

table AFTER age sex, c(mean var) pct

Assume for a moment that AFTER is a pre/post variable and that age and
sex are multichotomous. I'd then expect to see the values of var
listed in the before and after state arranged by age and sex and with
a new row that says pct change (from the AFTER variable).

Maybe I'm too wishful. :)

Dana

On Thu, Aug 27, 2009 at 8:35 PM, Eric A. Booth<[email protected]> wrote:
I got ahead of myself---to make the 'pctdiff' variable I should have
multiplied by 100, so it should read:

foreach v in 1991 1992 {
       gen pctdiff_var`v' = (var`v'/base_var1990)*100
       label var pctdiff_var`v' "Percent Change from `v' and 1990"
  }


EAB


On Aug 27, 2009, at 8:28 PM, Eric A. Booth wrote:

Dana:

I'm not sure that I completely understand how your data is structured, but I would use -tabout- to get at your main question--that of easily creating an excel table of the average % changes in some variable between a year and
a base year (or before & after some year).
I like to work with this kind of data in wide, rather than long, format, but you could adapt this same use of -tabout- to your data in long format.


**********************
clear
local sf `"`pwd'"'
input year var
1990 3
1991 4
1992 5
1990 7
1991 15
1992 3.2
1990 9
1992 3
end

          //SET-UP
gen id = [_n]
reshape wide var, i(id) j(year)
**
rename var1990 base_var1990
replace base_var1990 = base_var1990[_n-1] /*
*/  if base_var1990==.
foreach v in 1991 1992 {
       gen pctdiff_var`v' = (var`v'/base_var1990)
       label var pctdiff_var`v' "Percent Change from `v' and 1990"
  }


         //TABOUT EXAMPLE
tabout base_var1990 using "`sf'/test.xls", /*
*/  c(mean pctdiff_var1991 mean pctdiff_var1992) /*
*/  replace h1(TABLE Title) lines(double) f(2p) sum

**********************


Best,

Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754



On Aug 27, 2009, at 7:32 PM, Dana Chandler wrote:

Is there any module or easy way to calculate percentage changes in
stata? That is to say, a percentage change relative to some base
period. I am interested in an easy way to make a summary table of
percent changes to have exported to either excel or powerpoint.

Currently, supposing that my data has a "before" and "after"
observation in long form and then any number of other potential
categories, I either do a bunch of egens to create the totals and then
calculate the percent changes. Next, I "tag" whatever the unit of
observation is and then I make a table showing the mean of the percent
change. Alternatively, I could create and export a table that shows
the before and afters and then put that in excel and then calculate %
changes. Both processes seem really tedious.

Is there any easy way to do this in Stata?

Thanks in advance,
Dana
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index