Announcement

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

  • Time trends on pooled cross section data

    How do I plot income over time by gender, by race, by education level, for a pooled cross section data?

  • #2
    Abhishek, if you are going to plot average income over time by a group variable, you may generate the aggregate data for plotting using -collapse-.

    Code:
    collapse income, by(year gender)
    Then you may plot with the aggregate data.

    Code:
    twoway line income year if gender == 1 || line income year if gender == 2
    Above are example codes as I don't know about your actual data.

    Comment


    • #3
      Thank you so much Fei Wang.
      But then this will collapse the entire data, right? Is there no other way to do it? because once I collapse the data on mean values, I can't run regressions on individual data, right?

      Comment


      • #4
        Originally posted by Abhishek Maheshwari View Post
        Thank you so much Fei Wang.
        But then this will collapse the entire data, right? Is there no other way to do it? because once I collapse the data on mean values, I can't run regressions on individual data, right?
        Abhishek, there are several ways of handling this issue. For example, you may use -preserve- and -restore- to return to the original individual dataset after plotting with the aggregate data.

        Code:
        preserve
        collapse income, by(year gender)
        twoway line income year if gender == 1 || line income year if gender == 2
        graph save income_by_gender, replace
        restore
        
        * Now you have returned to the original individual data and may collapse another time or do other analyses.
        
        preserve
        collapse income, by(year race)
        twoway line income year if race == 1 || line income year if race == 2 || line income year if race == 3  ...
        graph save income_by_race, replace
        restore

        Comment


        • #5
          This is extremely helpful! Thank you so much!
          Let me try it...

          Comment


          • #6
            Professor Wang, Could you also tell how to plot income by percentile? I found the following code from an article ( https://www.theanalysisfactor.com/cr...bserve-trends/ )

            the code is:

            gen ptl=0 // variable for percentile

            preserve
            forvalues x=10(10)90{
            collapse (p`x’) wage1985-wage2005 (mean)ptl
            replace ptl=`x’
            save wage`x’,replace
            restore,preserve
            }
            use wage10,clear
            forvalues x=20(10)90{
            append using wage`x’
            save wage_ptl,replace
            }

            use wage_ptl,clear
            order ptl, first // moving the variable “ptl” to the top of the list

            ....(after that they use the xtset command etc.)


            Now, when I run the second part of it, all the wage values become zero (probably because of the CLEAR command)
            Please suggest.

            Thanks a lot.


            Comment

            Working...
            X