Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: question on line graphs


From   Michael Norman Mitchell <Michael.Norman.Mitchell@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: question on line graphs
Date   Sun, 18 Apr 2010 22:15:46 -0700

Dear Anant

  You are most welcome!

Note how the variable -rtax- was coded as 1 and 0. The -collapse- command creates the proportion of people who had a response of -1- on the outcome, broken down by cohort and year. So, that has replaced the original dataset in memory.

Indeed, you are right, that after that command has been issued, you would need to return to the original dataset for other analyses. You could, if you prefer, use the -preserve- command before -collapse- and -restore- after the -graph- command to return back to the dataset when the -preserve- command was issued.

Best regards,

Michael N. Mitchell
See the Stata tidbit of the week at...
http://www.MichaelNormanMitchell.com

On 2010-04-18 10.06 PM, Thaker, Anant wrote:
Dear Mitchell,

Thank you! This worked very well. Just a question: could you briefly explain the purpose of 'collapse rtax , by(cohort year)'? If I want to repeat this procedure with other variables, I'd have to reload the full GSS dataset, correct?

Thanks again,
Anant

Anant Thaker
MBA Class of 2011
Harvard Business School
athaker@mba2011.hbs.edu
+1 646-964-7123


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael Norman Mitchell
Sent: Sunday, April 18, 2010 11:32 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: question on line graphs

Dear Anant

    Will this do the trick...

******************************************
* CREATE FAKE DATASET
clear
set obs 10
generate year = 1995 + _n
expand 4
sort year
generate cohort = mod((_n-1),4)+1
tab year cohort
expand 100
generate tax = int(uniform()*5)+1
tab tax
recode tax (1 2=1 "1 or 2") (3 4 5=0 "3,4,5"), gen(rtax)
tab tax rtax
******************************************

* Start of real code

* collapse to get proportions
collapse rtax , by(cohort year)
* Convert to percentage
replace rtax = rtax*100
* separate into four variables by cohort
separate rtax, by(cohort)
* graph it
graph twoway (line rtax1 rtax2 rtax3 rtax4 year), ///
    xlabel(1996(1)2005, angle(45)) ///
    legend(label(1 "Cohort 1") label(2 "Cohort 2") label(3 "Cohort 3")
label(4 "Cohort 4"))

    And here is the graph that it creates

http://screencast.com/t/Y2FkZGQ0Y2U

    Hope that helps,

Michael N. Mitchell
See the Stata tidbit of the week at...
http://www.MichaelNormanMitchell.com

On 2010-04-18 8.06 PM, Thaker, Anant wrote:
I am a Stata 11/SE user. In my dataset, I have a cohort variable coded 1-4 with the various subgroups (e.g. 1 =<1934, 2 = 1934-1948, etc.), and an ordered variable that shows views on progressive taxation (coded 1-5 in terms of relative support). These data points are spread over a number of years (from the General Social Survey). I'm trying to chart out the % of respondents who selected 1 or 2 on the taxation variable, by cohort subgroup, over time. So the x-axis would be year, the y-axis would be "% who chose 1 or 2," and there would be four line graph series (one for each cohort subgroup). Would really appreciate some help! I can clarify as needed. Thanks!

Note: data is currently coded as this example:
YEAR  COHORT  TAXATION
2008  1965       1
YEAR  COHORT  TAXATION
1996  1975       3
...

Best,
Anant



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index