Announcement

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

  • Retrieval of marginal effects generated after a loop

    Dear members of the list,

    Using PIAAC data, I try to make a cross-national analysis of college graduation in 24 countries. My dependent variable is binary and my key independent variable is father's education (three categories). In this very preliminary stage of my analysis, I just control for age and gender.

    Instead of a standard multivelel logistic regression, I try to apply a two-step approach to my data: I run a logistic regression for each country first, I store the coefficients for father's education after each country analysis, and I then turn this per-country effect of father's education on college graduation into the dependent variable of the the second-stage analysis. My intention in this second step is to regress the cross-national variation in the effect of father's education to a number of country-level variables drawn from other sources different from PIAAC. But my query here is just related to the store and retrieval of the marginal effects to be obtained after the first step.

    Due to the complex sample design of PIAAC data, I need to use the weights provided by OECD in this database in order to obtain unbiased standard errors and correct statistics representative of the national population. Á Stata module was created for this purpose by Francesco Avvisati and François Keslair. Its name is repest

    Repest basically "embrace" other commands so that the analysis automatically includes all the necessary corrections.In the words of the authors of the module, "repest estimates statistics using replicate weights (BRR weights, Jackknife replicate weights,...), thus accounting for complex survey designs in the estimation of sampling variances. It is specially designed to be used with the IELS, PIAAC, PISA and TALIS datasets produced by the OECD, but works for ALL and IALS datasets as well. It also allows for analyses with multiply imputed variables (plausible values); where plausible values are included in a pvvarlist, the average estimator across plausible values is reported and the imputation error is added to the variance estimator"

    Here, there is one example provided at the bottom of the help file of this Stata module...

    PHP Code:
    repest PIAACestimate(statareg lnwage pvlityrsqual

    Using repest, I intend to create a loop that allows me to get unbiased standard estimators and correct statistics of each per-country logistic regression. In addtion to that, I intend to store, not the coefficients corresponding to my key independent variable (father's education) but the marginal effect of its constitutent categories. I do this because I assume that it is not correct to compare coefficients across logistic regressions corresponding to different national samples; it's preferable to use marginal effects. In particular, I try to use the difference in the marginal effect of the highest and lowest category of father's education. This difference will be the dependent variable in my second analysis.

    Now, to obtain postestimation results is not easy after repest. At the end of the help of this Stata module, the authors offer a loop for that that I have tried to replicate. It is as follows:

    PHP Code:
        User-defined estimation command2. logit postestimation

            cap program drop mylogitmargins
            program define mylogitmargins
    eclass
            syntax 
    [if] [in] [pweight], logit(string) [margins(string) loptions(string) moptions(string)]
            
    tempname b m
            
    // compute logit regressions, store results in vectors
                    
    logit `logit' [`weight' `exp'] `if' `in', `loptions'
                    
    matrix `b'= e(b)
            // compute logit postestimation, store results in vectors
                    if "
    `margins'" != "" | "`moptions'" != ""{
                            margins `margins', post `moptions'
                            matrix `m' = e(b)
                            matrix colnames `m' =  margins:
                            matrix `b'= [`b', `m']
                            }
            // post results
                    ereturn post `b' 
            end
        . repest PISA, estimate(stata: mylogitmargins, logit(repeat pv@math escs ib1.st04q01) margins(st04q01) moptions(atmeans)) 

    Following the advice of these authors, I have tried to create a loop that includes both the use of repest and the generation of postestimation results (marginal effects) in the same fashion as the authors of repest propose.

    1) First, I copy in my do-file the loop they propose

    PHP Code:
            cap program drop mylogitmargins
            program define mylogitmargins
    eclass
            syntax 
    [if] [in] [pweight], logit(string) [margins(string) loptions(string) moptions(string)]
            
    tempname b m
            
    // compute logit regressions, store results in vectors
                    
    logit `logit' [`weight' `exp'] `if' `in', `loptions'
                    
    matrix `b'= e(b)
            // compute logit postestimation, store results in vectors
                    if "
    `margins'" != "" | "`moptions'" != ""{
                            margins `margins', post `moptions'
                            matrix `m' = e(b)
                            matrix colnames `m' =  margins:
                            matrix `b'= [`b', `m']
                            }
            // post results
                    ereturn post `b' 
            end 

    2) I generate a variable that has subsequent numerical codes for the different countries in my sample:

    PHP Code:
    egen cntryid3_group=group(cntryid3), label 

    3) Finally, I run a loop of repest with the macro for postestimation result offered by the authors of repest:

    PHP Code:
    foreach i of numlist 1/24 {
           
    display "`: label (cntryid3_group) `i''"
           
    pe capture noisily repest PIAACestimate(statamylogitmarginslogit(univ i.edufath female age if cntryid3_group==`i' & egresados==1) margins(r.edufath))
           } 

    In the code above, 'univ' is my dep.variable; 'edufath' is my independent variable and 'female' and 'age' are controls.

    I would greatly appreciate if you could help me in two regards: 1) how could I retrieve the marginal effects that I have tried to generate for each country after "estimate(stata: mylogitmargins, logit(univ i.edufath female age if cntryid3_group==`i' & egresados==1) margins(r.edufath)"; 2) using "ereturn list", it seems that only the marginal effects and coefficients of the last country in the loop are stored. How could I get all?

    Thanks for your attention

    Luis Ortiz
Working...
X