Announcement

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

  • how to save variable coefficients as empty cell in stata

    I'm working on a trade issue with multiple country pairs and years. my dependent variable is unit value between countries and main independent variables are tariff between countries and trade policy dummy variables.

    Now I encounter a problem in my code. here is part of my code:

    forvalues n == 1/380{
    cap noisily qui ppml lnuv lntariff`n' intcounp`n' mp2 edds labord capitald agrid fta_wto eud wtod ADP CV QR SG SPS SSG STE TRQ XS counprod* time*, cluster(countryproduct)
    capture noisily mat coef_lntariff`n' = _b[lntariff`n']
    capture noisily mat coef_tariff`n' = nullmat(coef_tariff`n')\coef_lntariff`n'
    capture noisily svmat coef_tariff`n', names(coef_lntariff`n')
    capture noisily mat se_lntariff`n' = _se[lntariff`n']
    capture noisily mat se_tariff`n' = nullmat(se_tariff`n')\se_lntariff`n'
    ...

    in the above code, n is country pair id( n = 1, 2 , 3...). I want to save the coefficients of tariff variable(lntariff) and trade policy dummy variables(intcounp). however, in some country pairs, the tariff is all zero across my sample time, which would result to PPML drop the tariff variable(lntariff) or sometimes, this trade policy is not used in certain country pairs, which lead to trade policy dummy variable(intcounp) be zero, then again, PPML would drop this variable.

    I'm wordering if there is any way to still store the coefficients of tariff variable (lntariff) and trade policy variable( intcounp) as empty cell even when they are all zero and PPML drop them.

    ultimately, I want to achieve something like this:

    Click image for larger version

Name:	1532703221(1).png
Views:	1
Size:	20.7 KB
ID:	1455319


    countrypair is the country pair id variable, coef_lntariff is the coefficient of lntariff, se is the standard error...
    each coefficient is corresponding to the country pair id.

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stat output, and sample data using dataex (or illustrate the problem using a Stata supplied data set). Simplify what you post to the minimum needed to demonstrate your problem.

    I can't easily replicate your problem so I can't diagnose and fix the problem. I looks like you're creating 380 matrices and then need another loop to join them all. I'd think it would be simpler to have one matrix with a you would want a row or column condition when you write to the matrix. I would have thought that you'd get a missing in the matrix if _b[lntariff`n'] was not included in the regression. If not, then do
    if _b[lntariff`n'] <. {
    mat coef_lntariff`n' = _b[lntariff`n']
    }
    if _b[lntariff`n'] ==. {
    mat coef_lntariff`n' = .
    }

    Again, I can't check if this works without your data and code.

    Comment

    Working...
    X