Announcement

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

  • on implementing 2SRI/CF through Prof Terza's code - Matrix multiplication is not happening due to error 3200

    Hi
    I am working with DHS data on implementing the Control Function approach following Prof Terza's guide. I use STATA 17.

    Endogenous regressor: Women's Occupation
    Instrument: Cluster Average of Women's Occupation
    Outcome Variable: IPV
    I am doing probit estimation, where most counterfactuals are categorical variables.
    Number of observations: 9342

    I followed Terza's code
    HTML Code:
    https://pmc.ncbi.nlm.nih.gov/articles/PMC5980262/
    - ran both stages, generated residuals, saved X and W matrices


    The following step of matrix multiplication runs into conformability error (3200) in my context:
    Code:
    /*step i*/
    mata: gradbeta=exp(X*betahat):*X
    mata: gradalpha=-Bu:*normalden(X*betahat):*exp(W*alphahat):*W



    I checked for dimensions of the matrices and realised the mismatch:
    Code:
    . display "Dimensions of X: " n_rows_X "x" n_cols_X
    Dimensions of X: 9342x23
    
    . display "Dimensions of betahat: " n_rows_betahat "x" n_cols_betahat
    Dimensions of betahat: 83x1
    I assume the dimensional mismatch between 23 and 83 is the issue. Is this because of the categorical variables involved in the estimation? - When I include categorical variables, the model will estimate one coefficient for each dummy variable. If I have many categorical variables with multiple categories, the total number of estimated coefficients will increase beyond the number of original variables in the matrix X.


    How do I work around this and achieve coformability that ensures matrix multiplication? Any help will be much appreciated.

    Thank you
    Last edited by steny rapheal; 22 Feb 2025, 05:01.
Working...
X