Announcement

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

  • Could anyone please help me to fix this GMM wrapper program?

    I'm trying to estimate the conditional logit model using GMM and trying to write a wrapper program. The theory of the model is attached in the theory file. My program looks like the following (with an example data):
    HTML Code:
    clear all
    program define clsvywt, eclass byable(recall)  
        
        version 15.1
        syntax varlist(numeric min=2 ts fv) [if] [in], GRoup(varname)
        marksample touse //sample restrictions
        
        quietly count if `touse'
        if `r(N)' == 0 {
            error 2000
        }
        gettoken depvar indepvars : varlist //parsing dependent and independent variables
        _fv_check_depvar `depvar' //allowing the dependent variable as a factor variale
        
        local den = "exp({xb: `indepvars'})" 
        local dist = "bysort `group' : sum(exp({xb: }))"
        
            
        local first(first: (`depvar' - (`den'/`dist'))) 
        
        local first_inst instruments(first: `indepvars', noconstant) 
            
        gmm `first', `first_inst' onestep winitial(unadjusted, independent) 
        
    end
    
    use http://www.stata-press.com/data/r15/clogitid
    clsvywt y x1 x2, gr(id)
    My problem lies in the " local dist = "bysort `group' : sum(exp({xb: }))" " macro. I think I made my mistake in that line because if I drop that line and run the program works. I also provide here the program by dropping that line:

    HTML Code:
    clear all
    program define clsvywt, eclass byable(recall)  
        
        version 15.1
        syntax varlist(numeric min=2 ts fv) [if] [in], GRoup(varname)
        marksample touse //sample restrictions
        
        quietly count if `touse'
        if `r(N)' == 0 {
            error 2000
        }
        gettoken depvar indepvars : varlist //parsing dependent and independent variables
        _fv_check_depvar `depvar' //allowing the dependent variable as a factor variale
        
        local den = "exp({xb: `indepvars'})" 
            
        
        local first(first: (`depvar' - `den')) 
        
        local first_inst instruments(first: `indepvars', noconstant) 
            
        gmm `first', `first_inst' onestep winitial(unadjusted, independent) 
        
    end
    
    use http://www.stata-press.com/data/r15/clogitid
    clsvywt y x1 x2, gr(id)
    Could anyone please help me to fix this part, either providing a logical explanation or guiding me with some resources or directing me in writing that macro properly? It will be a great help for me.

    Thank you in advance.
    Attached Files
Working...
X