Announcement

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

  • Panel Data Graph Mean (&SE) - Including Lines for Various Groups

    Dear Statalist,
    I have a large panel dataset with various waves/periods and many variables in a long format. Now I want to loop over a set of variables to give me plots for preliminary visual inspection.
    The graphs I want to produce ideally include the mean and standard errors of the mean for all observations and also means and standard errors for observations by groups (i.e. socioeconomic status and migration background).
    For example, I have a variable of language skills that I want to plot with its mean and standard errors over the waves. Now I also want to add further lines within the same graph by high and low socioeconomic status (ses) and also by migration background (native and migration background), so that I have five lines in my graph in total.

    So far, I have managed to create the graphs separately, but not in one graph, as the -grcomb- command does not let me combine various grouping variables. Of course, one could respecify the grouping variable (so that we have one variable of ses and migration background in four classes - native high, native low, migrant high, migrant low - but that is not exactly what I want.), or do some -graph combine- shenanigans (which is a bit tiresome to look at).

    My code for this is the following:
    Code:
    ds *, has(type numeric)
    local variables `r(varlist)' 
    foreach var of local variables {
    lgraph `var' wave, err(semean) 
    graph export "...", replace
    grcomb lgraph `var' wave ses, v(3) err(semean) 
    graph export "...", replace
    grcomb lgraph `var' wave mig, v(3) err(semean) 
    graph export "...", replace
    }
    Also, I have the feeling this question must have been posted various times, but I simply cannot seem to find the correct post. It would also help me greatly if you could refer me to some similar Q&A.
    Thank you all so much in advance for your help.
    All the best,
    Fabian

  • #2
    lgraph and grcomb are from SSC. Neither is a command I can advise on, and indeed I have not worked out what grcomb would do exactly.

    But you could perhaps loop over your variables and then apply graph combine.


    I can't test this, but the code must be run all at once as a script.


    Code:
    ds *, has(type numeric)
    local variables `r(varlist)' 
    
    local graphs 
    
    foreach var of local variables {
        lgraph `var' wave, err(semean) name(`var')
        lgraph `var' wave ses, v(3) err(semean) name(`var'_ses)
        lgraph `var' wave mig, v(3) err(semean) name(`var'_mig)
        local graphs `graphs' `var' `var'_ses `var'_mig 
    }
    
    graph combine `graphs'

    Comment

    Working...
    X