Announcement

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

  • Dynamic ML model code syntax error for simulation of maximum likelihood

    Hello, could someone help me identify what is the problem with this code I tweaked to simulate maximum likelihood in a dynamic multinomial logit model from this article by Haan & Uhlendorf "Estimation of multinomial logit models with unobserved heterogeneity using maximum simulated likelihood": https://journals.sagepub.com/doi/pdf...867X0600600205

    I am getting the error that there is an invalid syntax. Thank you!


    program define mlogitmodeld0
    args todo b lnf
    tempvar etha2 etha3 random1 random2 lj pi1 pi2 pi3 sum lnpi L1 L2 last
    tempname lnsig1 lnsig2 atrho12 sigma1 sigma2 cov12
    mleval `etha2' = `b', eq(1)
    mleval `etha3' = `b', eq(2)
    mleval `lnsig1' = `b', eq(3) scalar
    mleval `lnsig2' = `b', eq(4) scalar
    mleval `atrho12' = `b', eq(5) scalar
    qui {
    scalar `sigma1'=(exp(`lnsig1'))^2
    scalar `sigma2'=(exp(`lnsig2'))^2
    scalar `cov12'=[exp(2*`atrho12')-1]/[exp(2*`atrho12')+1]* ///
    (exp(`lnsig2'))*(exp(`lnsig1'))
    gen double `random1' = 0
    gen double `random2' = 0
    gen double `lnpi'=0
    gen double `sum'=0
    gen double `L1'=0
    gen double `L2'=0
    by personid: gen byte `last'=(_n==_N)
    gen double `pi1'=0
    gen double `pi2'=0
    gen double `pi3'=0
    }
    matrix W = ( `sigma1' , `cov12' \ `cov12' , `sigma2')
    capture matrix L=cholesky(W)
    if _rc != 0 {
    di "Warning: cannot do Cholesky factorization of rho matrix"
    }
    local l11=L[1,1]
    local l21=L[2,1]
    local l22=L[2,2]
    forvalues r=1/$draws{
    qui {
    replace `random1' = random_1`r'*`l11'
    replace `random2' = random_2`r'*`l22' + random_1`r'*`l21'
    replace `pi1'= 1/(1 + exp(`etha2'+`random1')+exp(`etha3'+`random2'))
    replace `pi2'= exp(`etha2'+`random1')*`pi1'
    replace `pi3'= exp(`etha3'+`random2')*`pi1'
    replace `lnpi'=ln(`pi1'*a1+`pi2'*a2+`pi3'*a3)
    by personid: replace `sum'=sum(`lnpi')
    by personid: replace `L1' =exp(`sum'[_N]) if _n==_N
    by personid: replace `L2'=`L2'+`L1' if _n==_N
    }
    }
    qui gen `lj'=cond(!`last',0, ln(`L2'/`$draws'))
    qui mlsum `lnf'=`lj'
    if (`todo'==0|`lnf'>=.) exit
    end

    ml model d0 mlogitmodeld0 (newstates = married yearseduc hhsize nchild ndependents h2q8 agesq altisco_1-altisco_9 tenure year_1-year_7 newstates_1t_1 newstates_2t_1 newstates_3t_1 newstates_1t1 newstates_2t1 newstates_3t1) (newstates = married yearseduc hhsize nchild ndependents h2q8 agesq altisco_1-altisco_9 tenure year_1-year_7 newstates_1t_1 newstates_2t_1 newstates_3t_1 newstates_1t1 newstates_2t1 newstates_3t1) /lnsig1 /lnsig2 /atsig12

    matrix start = (Init)

    ml init start 0.5 0.5 0.5 ,copy

    ERROR:
    . ml maximize

    invalid syntax
    r(198);
    Last edited by Julia Smith; 26 May 2020, 18:46.

  • #2
    I'm sorry for my ignorance! I noticed several errors in the above program and fixed them.
    Now I get an r(503) error when I try to run this code:
    Code:
    ml init start 0.5 0.5 0.5 ,copy
    Code:
    . ml init start 0.5 0.5 0.5 ,copy
    initial vector: matrix must be dimension 41
    r(503);
    I used the exact code as in the article. I only replaced "school" with "personid" as I am working with panel data.
    I run all the draws with mdraws and I am fairly confident about that part.
    I am able to complete
    Code:
    ml maximize
    even with the above error but I wonder what the problem is. Thank you!
    Code:
    global xvars married yearseduc hhsize nchild ndependents h2q8 agesq tenure altisco_1-altisco_9 h2q3
    mlogit newstates $xvars, base(1) vce(robust)
    matrix Init = e(b)
    sort personid
    program define mlmodel1
    args todo b lnf
    tempvar etha2 etha3 random1 random2 lj pi1 pi2 pi3 sum lnpi L1 L2 last
    tempname lnsig1 lnsig2 atrho12 sigma1 sigma2 cov12
    mleval `etha2' = `b', eq(1)
    mleval `etha3' = `b', eq(2)
    mleval `lnsig1' = `b', eq(3) scalar
    mleval `lnsig2' = `b', eq(4) scalar
    mleval `atrho12' = `b', eq(5) scalar
    qui {
    scalar `sigma1'=(exp(`lnsig1'))^2
    scalar `sigma2'=(exp(`lnsig2'))^2
    scalar `cov12'=[exp(2*`atrho12')-1]/[exp(2*`atrho12')+1]*(exp(`lnsig2'))*(exp(`lnsig1'))
    gen double `random1' = 0
    gen double `random2' = 0
    gen double `lnpi'=0
    gen double `sum'=0
    gen double `L1'=0
    gen double `L2'=0
    by personid: gen byte `last'=(_n==_N)
    gen double `pi1'=0
    gen double `pi2'=0
    gen double `pi3'=0
    }
    matrix W = ( `sigma1'  , `cov12'  \  `cov12'  ,  `sigma2')
    capture matrix L=cholesky(W)
    if _rc != 0 {
    di "Warning: cannot do Cholesky factorization of rho matrix"
    }
    local l11=L[1,1]
    local l21=L[2,1]
    local l22=L[2,2]
    forvalues r=1/$draws{
    qui {
    replace `random1' = random_1`r'*`l11'
    replace `random2' = random_2`r'*`l22' + random_1`r'*`l21'
    replace `pi1'= 1/(1 + exp(`etha2'+`random1')+exp(`etha3'+`random2'))
    replace `pi2'= exp(`etha2'+`random1')*`pi1'
    replace `pi3'= exp(`etha3'+`random2')*`pi1'
    replace `lnpi'=ln(`pi1'*ns_1 +`pi2'*ns_2 +`pi3'*ns_3)
    by personid: replace `sum'=sum(`lnpi')
    by personid: replace `L1' =exp(`sum'[_N]) if _n==_N
    by personid: replace `L2'=`L2'+`L1' if _n==_N
    }
    }
    qui gen `lj'=cond(!`last',0, ln(`L2'/$draws))
    qui mlsum `lnf'=`lj'
    if (`todo'==0|`lnf'>=.) exit
    end
    ml model d0 mlmodel1 (newstates = married yearseduc hhsize nchild ndependents h2q8 agesq altisco_1-altisco_9 tenure h2q3) (newstates = married yearseduc hhsize nchild ndependents h2q8 agesq altisco_1-altisco_9 tenure h2q3) /lnsig1 /lnsig2 /atsig12
    matrix start = (Init)
    ml init start 0.5 0.5 0.5 ,copy
    ml maximize
    Last edited by Julia Smith; 27 May 2020, 04:32. Reason: Poor editing: sorry!

    Comment


    • #3
      Several suggestions: (1) report Stata code input and output using CODE delimiters. (Please reread the Forum FAQ about this -- hit the black bar at the top of the page.) (2) Layout your code in a more readable manner, especially using e.g. indentations for continuation lines, blocks inside loops, etc. Without doing these sorts of things, your code is much less legible than is desirable if you're trying to interest readers in your problem. Frankly, as things stand, I for one am unwilling to look at your code or error tracing at all. It would also help if you told us precisely what is the same as Haan & Uhlendorf's code in your code, and precisely what you have changed. (All this relates to posing a well-formed question; again, see the FAQ about this.)

      Also be aware that this sort of model can nowadays also be fitted using gsem. Look at e.g. Example 41g in the SEM manual.

      Comment


      • #4
        Dear Stephen Jenkins thank you for your correction. Yes it looked quite ugly, I'm sorry.
        I have fixed it now. I hope you can help me with any suggestions now. I looked at the gsem example but it does not mention anything about panel data and I am very new to all this so it seems more complicated than following through with codes that have a similar problem.

        Comment


        • #5
          The issue is not "ugliness"; it is illegibility and clarity.

          Example 41g refers to a "multi-level" MNL model. A panel data model in which you treat the intercepts as random is a "multi-level" model. (The point is that you have repeated measurements on your units.) One practical implementation issue is that gsem (if I recall correctly) requires data in wide format, whereas most "panel data" models in Stata, as in the xt suite, work with data in long format.

          Comment


          • #6
            I have a related question
            I have the following program, It works very well, the problem is I need to predict the linear combinations following this program:
            ///////////////////////////////////////////////////////////////////////
            capture program drop garchsk
            program garchsk
            version 17
            args lnf a1 b0 b1 b2 c0 c1 c2 g0 g1 g2
            tempvar et yt ht nt st kt psi gam

            * initialize variables
            qui gen double `yt'=$ML_y1
            qui gen double `et'=0.0

            qui sum `yt', detail
            qui gen double `ht'=r(Var)
            qui gen double `nt'=`et'/sqrt(`ht')
            qui gen double `st'=r(skewness)
            qui gen double `kt'=r(kurtosis)

            * make garch11 for var, skew , kurtosis. There is AR1 in the mean equation (for et)
            qui replace `et'=`yt'-`a1'*`yt'[_n-1] if _n>1
            qui replace `ht'=`b0'+`b1'*(`et'[_n-1])^2 + `b2'*`ht'[_n-1] if _n>1
            qui replace `nt'=`et'/sqrt(`ht')
            qui replace `st'=`c0'+`c1'*(`nt'[_n-1])^3 + `c2'*`st'[_n-1] if _n>1
            qui replace `kt'=`g0'+`g1'*(`nt'[_n-1])^4 + `g2'*`kt'[_n-1] if _n>1

            * make Gram-Charlier liklelihood(lnf)
            qui gen double `psi'= 1 + (`st'/6) * ((`nt'^3)-(3*`nt'))+((`kt'-3)/24)*(`nt'^4 - (6*`nt'^2) + 3)
            qui gen double `gam'= 1+ ((`st'^2)/6) +(((`kt'-3)^2)/24)
            qui replace `lnf'= -0.5*ln(`ht')-0.5*(`nt'^2) +ln(`psi'^2)-ln(`gam')



            end

            ml model lf garchsk (a1: ret= ) /b0 /b1 /b2 /c0 /c1 /c2 /g0 /g1 /g2, technique(bhhh) robust

            ml init /b0=0.0023 /b1=0.0387 /b2=0.9586 /c0=-0.0458 /c1=0.0085 /c2=0.0227 /g0=3.0471 /g1=0.0055 /g2=0.0882

            ml search
            ml max
            ml graph

            ml model lf garchsk (a1: ret= ) /b0 /b1 /b2 /c0 /c1 /c2 /g0 /g1 /g2, technique(bhhh) robust

            *ml init b0=0.000024 /b1=0.038 /b2=0.23 /c0=-0.2 /c1=-0.085 /c2=0.57 /g0=3.12 /g1=0.033 /g2=-0.39
            ml init /b0=0.0023 /b1=0.0387 /b2=0.9586 /c0=-0.0458 /c1=0.0085 /c2=-0.0227 /g0=3.0471 /g1=0.0055 /g2=0.0882

            ml report
            ///////////////////////////////////////////
            I think the right command is mleval `newvar' =`st', eq(#)
            well I have tried that, but it always gives me an error, so I guess I have to specify the equation. I tried to do that, right after the n>1 for the mean equations. and I still get the exact same error.
            If anyone can help me to modify the program to predict `ht', `st', and `kt', that you be highly appreciated.

            Sarah

            Comment


            • #7
              I suspect the appropriate command to predict the linear combinations is predict rather than mleval.

              Comment


              • #8
                well predict doesn't work in here. it provides a scalar for all observation.
                Thank you though

                Comment


                • #9
                  Originally posted by Sarah Hussein View Post
                  well predict doesn't work in here. it provides a scalar for all observation.
                  Thank you though
                  Can you elaborate on what your "linear combinations" refer to? Your model specification:

                  ml model lf garchsk (a1: ret= ) /b0 /b1 /b2 /c0 /c1 /c2 /g0 /g1 /g2, technique(bhhh) robust

                  doesn't include any equation that varies from observation to observation. The vector of coefficients for each equation, therefore, is a scalar and it is not surprising that the linear combination of one scalar that you -predict- turns out to be a scalar.

                  Comment


                  • #10
                    @Hong Il Yoo
                    Originally posted by Hong Il Yoo View Post

                    Can you elaborate on what your "linear combinations" refer to? Your model specification:

                    ml model lf garchsk (a1: ret= ) /b0 /b1 /b2 /c0 /c1 /c2 /g0 /g1 /g2, technique(bhhh) robust

                    doesn't include any equation that varies from observation to observation. The vector of coefficients for each equation, therefore, is a scalar and it is not surprising that the linear combination of one scalar that you -predict- turns out to be a scalar.
                    the purpose of this program is to estimate the conditional variance `ht', conditional skewness `st' and conditional kurtosis `kt', so I want a vector of ht, st and kt following the equations as defined in the program, in other words, l want to obtain the values of each of the linear predictors of each equation from it.
                    I believe the correct way to do that is to put thatas part of the program, as to calculate these conditional moments each period and update that, yet I fail to do that within the program.
                    this is very crucial to my work, otherwise there is no use of this program.

                    Thanks in advance,
                    Last edited by Sarah Hussein; 22 Aug 2021, 10:39.

                    Comment


                    • #11
                      Sara Hussein: If I understood you correctly, once you have obtained your point estimates, you can generate ht, st, and kt using exactly the same formulas as you have used in the program. For example,

                      generate double et = ret - _b[a1:_cons]*ret[_n-1] if _n>1 & e(sample)
                      generate double ht = _b[/b0]+_b[/b1]*(et[_n-1])^2 + _b[/b2]*ht[_n-1] if _n>1 & e(sample)

                      and so on.

                      Comment


                      • #12
                        Originally posted by Hong Il Yoo View Post
                        Sara Hussein: If I understood you correctly, once you have obtained your point estimates, you can generate ht, st, and kt using exactly the same formulas as you have used in the program. For example,

                        generate double et = ret - _b[a1:_cons]*ret[_n-1] if _n>1 & e(sample)
                        generate double ht = _b[/b0]+_b[/b1]*(et[_n-1])^2 + _b[/b2]*ht[_n-1] if _n>1 & e(sample)

                        and so on.
                        I have tried what you proposed, as follows:
                        //////////////////////////////
                        gen double et = ret - _b[a1:_cons]*ret[_n-1] if _n>1 & e(sample)

                        qui gen double ht=(_b[/b0])/(1-_b[/b1]-_b[/b2])
                        qui gen double nt=et/sqrt(ht)
                        qui gen double st=(_b[/c0])/(1-_b[/c1]-_b[/c2])
                        qui gen double kt=(_b[/g0])/(1-_b[/g1]-_b[/g2])

                        qui replace ht = _b[/b0]+_b[/b1]*(et[_n-1])^2 + _b[/b2]*ht[_n-1] if _n>1 & e(sample)

                        qui replace st = _b[/c0]+_b[/c1]*(nt[_n-1])^3 + _b[/c2]*st[_n-1] if _n>1 & e(sample)

                        qui replace kt = _b[/g0]+_b[/g1]*(nt[_n-1])^4 + _b[/g2]*kt[_n-1] if _n>1 & e(sample)

                        /////////////////
                        however, it gave me a vector for et, but not for the conditional moments (ht, st, and kt), it just calculated the first observation.

                        Comment


                        • #13
                          Sarah Hussein: I think you'll be able to get more useful advice if you elaborate on your problem (e.g., you can perhaps show us what your data look like and tell us if you're seeing any error message).

                          Based on the fragments of information that I have, one quick and dirty solution I can suggest is for you to -generate- et, ht, nt, st, and kt as Stata variables before you define your program. For example:
                          HTML Code:
                          generate double et = .
                          generate double ht = .
                          and so on before you type -program garchsk-. Then, inside your program, you can use those variables in place of their namesake temporary variables. For example:
                          HTML Code:
                          qui replace et = 0.0
                          qui replace ht =r(Var)
                          qui replace nt = et/sqrt(ht)
                          qui replace et =`yt'-`a1'*`yt'[_n-1] if _n>1
                          qui replace ht =`b0'+`b1'*(et[_n-1])^2 + `b2'*ht[_n-1] if _n>1
                          and the like. I would have preferred to write a separate postestimation program to predict the conditional moments, but my guess is that this quick and dirty solution will also give you what you're after at the end of the estimation run.

                          Comment


                          • #14
                            Originally posted by Hong Il Yoo View Post
                            Sarah Hussein: I think you'll be able to get more useful advice if you elaborate on your problem (e.g., you can perhaps show us what your data look like and tell us if you're seeing any error message).

                            Based on the fragments of information that I have, one quick and dirty solution I can suggest is for you to -generate- et, ht, nt, st, and kt as Stata variables before you define your program. For example:
                            HTML Code:
                            generate double et = .
                            generate double ht = .
                            and so on before you type -program garchsk-. Then, inside your program, you can use those variables in place of their namesake temporary variables. For example:
                            HTML Code:
                            qui replace et = 0.0
                            qui replace ht =r(Var)
                            qui replace nt = et/sqrt(ht)
                            qui replace et =`yt'-`a1'*`yt'[_n-1] if _n>1
                            qui replace ht =`b0'+`b1'*(et[_n-1])^2 + `b2'*ht[_n-1] if _n>1
                            and the like. I would have preferred to write a separate postestimation program to predict the conditional moments, but my guess is that this quick and dirty solution will also give you what you're after at the end of the estimation run.
                            ////////////data generated by dataex is:
                            . dataex

                            ----------------------- copy starting from the next line -----------------------
                            Code:
                            * Example generated by -dataex-. For more info, type help dataex
                            clear
                            input double(ndate cegn ces pop pd_cegn pd_ces grcon2_q defl) byte nber
                            1947.25  74.872  60.695   101799.864879566 16.217  8.383                   -99 12.709622614648106 0
                             1947.5  76.898  61.908  102021.9210454717 16.375  8.429   .013184518366364806 12.831054003429248 0
                            1947.75  78.648  63.249 102244.46158275525  16.67  8.631 -.0017345802206563126 13.086705702023302 0
                               1948  79.966  64.344  102467.4875479765 17.175  8.826   -.01050030075309305  13.45240242533435 0
                            1948.25  81.546  65.406             102691 17.457  8.876    .00564865741222631  13.63773325983995 0
                             1948.5  83.169  67.084             102915 17.631  8.964   .011088536695042617 13.761413183097844 0
                            1948.75  83.466  68.461             103249 17.803  9.099 -.0023054600081368667 13.880823270386434 0
                               1949  83.686  69.404             103418 17.619  9.133   .009495105047792371 13.771835952707558 0
                            1949.25  82.732  69.799             103584 17.351  9.127      .003779252001131  13.58765369006956 1
                             1949.5  81.894    70.3             103838 17.127  9.147  .0016889630986096356 13.440954557998342 1
                            1949.75  80.255  70.376             104127 16.933  9.176  -.007443872631448061 13.308867968744813 1
                               1950  80.949  71.085             104428 16.804  9.241   .005176572857716078 13.267844567662495 1
                            1950.25  81.465  72.265             104733 16.697  9.279    .00959065693360009 13.209965784167045 0
                             1950.5  82.788  74.365             105020 16.774  9.313    .01708102505195928  13.24344528580428 0
                            1950.75  86.633  76.665             105248 17.255  9.456   .013780801703994186 13.593532407010496 0
                               1951  86.651  78.147             104982 17.651  9.578 -.0020625261231999406 13.822793765701041 0
                            1951.25  91.967  81.751             104692 18.396  9.753    .02645729448243737 14.328638569405587 0
                             1951.5  91.446  82.908             104507 18.563  9.825  .0005192958792635998 14.407947038783165 0
                            1951.75  93.171  84.395             104543 18.524  9.878    .01515465093372161 14.414659416780239 0
                               1952  95.454  85.889             104747 18.758 10.028   .003937958740548701 14.623233452628444 0
                            1952.25  94.762  87.556             104863 18.777 10.097   .003610861498708179  14.60853566844744 0
                             1952.5    96.6  89.621             105007 18.706 10.177   .016841936325444996  14.60132056534977 0
                            1952.75  98.474  91.774             105343 18.739 10.285   .011568260984427424 14.660863062949415 0
                               1953 100.331  93.802             105703 18.817 10.364   .010913537702457293 14.732643883317108 0
                            1953.25 100.517  95.761             106672 18.735 10.474 -.0004549695093183457 14.704585888382802 0
                             1953.5 100.556  97.649             106905 18.657 10.554   .007019414354537054  14.66492186372695 0
                            1953.75  99.843  99.529             107140 18.696 10.693 -.0017749052770539109 14.700802143731314 1
                               1954  99.959   99.77             107503  18.69 10.798  -.007505350324675326 14.747734029610125 1
                            1954.25 101.262 101.274             107877 18.753  10.86   .005891899658933532  14.80626617490224 1
                             1954.5 101.324 103.224             108177 18.815 10.881   .007137169245687829 14.811151436337683 1
                            1954.75 102.197 105.199             108443  18.74   10.9   .013076095203552716 14.763259079249357 0
                               1955 103.431  106.94             108786 18.652 10.948   .010557690772786676 14.735748425400843 0
                            1955.25 104.502 108.825             109130 18.652 11.011   .008059058280417248 14.754078850778383 0
                             1955.5 106.123 110.017             109534 18.598 11.051   .007575028460808894 14.756516244101045 0
                            1955.75 106.942 111.686             109884 18.616 11.105  .0057318952518238195  14.77900955961725 0
                               1956 109.047 114.593             110186 18.605 11.172   .017082199743293974 14.796335320157397 0
                            1956.25 110.542 116.369             110483 18.649 11.237   .007496229263518103 14.847831136436753 0
                             1956.5 111.292 118.163             110788 18.823 11.302  .0024023350884224627 14.949892318755312 0
                            1956.75 112.431 120.405             111113 19.003 11.397   .003981450891518096 15.069757589032625 0
                               1957 113.676 122.723             111431  19.06 11.467   .008321393866753674  15.11820778006675 0
                            1957.25 115.415  124.32             111720 19.236 11.571   .002058692419485735 15.261141093290508 0
                             1957.5 116.479 125.971             112045  19.34 11.626  .0038764716648073635 15.331997137554136 0
                            1957.75 119.354 127.961             112431 19.546 11.724   .006170529995075702 15.498890273537796 0
                               1958 119.053 130.283             112866 19.625 11.809  .0007193784247431145 15.540985144543908 1
                            1958.25 119.862 131.073             113236 19.938 11.895 -.0072581437024302285 15.736831813019307 1
                             1958.5 121.184 133.429             113532 19.977 11.936   .009875059553054207 15.763143720077139 0
                            1958.75 123.027 135.885             113846 19.917 11.992   .012397245099946757 15.757715667871711 0
                               1959 126.074 139.726             114283 17.792 11.344    .09893065868655372 14.402409149736643 0
                            1959.25 127.152 142.888             114714 17.797 11.429    .00871430228742412  14.42745925048141 0
                             1959.5 128.188 146.201             115139 17.873 11.538   .006259625785357796 14.497560988232035 0
                            1959.75 129.461 149.277             115551  17.94 11.639   .006381682714475288 14.565525127539122 0
                               1960 129.605 151.304             115918 17.915 11.691   .003514634566270028  14.56261151832088 0
                            1960.25 131.961 153.813             116708 18.043 11.755   .004162288027111115  14.65859083751496 0
                             1960.5  131.58 154.623             117037 18.097 11.831  -.005685392151420185 14.711753451221686 1
                            1960.75 132.413 156.921             117411 18.199 11.892   .003240144945248272 14.778383179992675 1
                               1961 133.401 158.878             117824 18.226 11.923   .004916430720447031 14.799794100842002 1
                            1961.25 134.245 161.891             118254 18.099 11.975   .010389523376202248 14.751144676770133 0
                             1961.5 134.596 163.156             118636 18.132 12.032  -.000985118512217008 14.789447808914803 0
                            1961.75 136.167 166.742             119001 18.098 12.082   .013069043739444853 14.786378780425805 0
                               1962 137.832 169.287             119190 18.169 12.152  .0073843093116727635 14.852370683676359 0
                            1962.25 138.745 172.666             119379 18.217 12.211    .00948657166360674 14.886892855422577 0
                             1962.5  139.96 174.806             119819 18.235 12.258   .004536482199591152   14.9156597218251 0
                            1962.75 141.477 177.594             120368  18.33   12.3   .005450825265495598 14.973719360267774 0
                               1963 142.458 179.236             121046 18.356 12.358 -.0007717053630802787 15.014136216404411 0
                            1963.25 142.803 181.728             121640 18.338 12.398  .0031853148742582525 15.011771319226824 0
                             1963.5 145.166 185.526             122167 18.473  12.44   .010132973156557345 15.088344919139258 0
                            1963.75 145.279 189.031             122670  18.51 12.505   .004337931199656794 15.114555188298285 0
                               1964 148.651 192.935             123189 18.621 12.563   .011986652063373834 15.199313426194283 0
                            1964.25 151.455 196.604             123708 18.617 12.624   .011471499050812194 15.231804467058746 0
                             1964.5 154.877 200.168             124203 18.673 12.685   .011281391914049449 15.297073049895081 0
                            1964.75   155.8 203.811             124739 18.749  12.74  .0053435799072013715  15.34337475772432 0
                               1965  157.76 207.035             125289 18.806 12.795   .006331222879755009 15.394529489165146 0
                            1965.25 160.768 211.056             125814 18.984 12.849    .00894863729014414 15.501630491845603 0
                             1965.5 164.069 215.035             126325 19.088 12.915    .00994552666706083 15.586556979087533 0
                            1965.75 170.545 220.065             126745 19.131 12.997   .020214046612184355 15.675177798827473 0
                               1966 174.094  223.73             127169 19.388 13.078   .005912757644813953 15.839354619128057 0
                            1966.25 177.238  228.23             127511 19.552 13.197   .007694949488191515 15.974894901693846 0
                             1966.5  179.77 232.198             127869 19.689 13.317   .005043269033968593 16.097542275128166 0
                            1966.75 180.394  237.04             128234 19.812 13.448  .0033416941611778233 16.198201028186496 0
                               1967 182.375 240.841             128617 19.807  13.54   .006818205881365688 16.240616529148234 0
                            1967.25 184.021 244.953             129044 19.838 13.638   .005620446592282278  16.29767214796235 0
                             1967.5 185.777 250.241             129527 20.046 13.745   .004900411552127003 16.429707688673403 0
                            1967.75 187.864 254.743             130166 20.181 13.876   .002114831522572468 16.552149541240876 0
                               1968 193.535 261.903             130757  20.39 14.045    .01237137624093867 16.741260687513996 0
                            1968.25 197.769 269.161             131267 20.583 14.214   .010418965151043659 16.911600841667916 0
                             1968.5 202.841 275.736             131712  20.78 14.378   .010334344771757641 17.091436044774408 0
                            1968.75 205.007 282.144             132250 20.997 14.552  .0032679303549224695 17.264239356996082 0
                               1969 208.834 288.161             132880 21.154 14.734   .004715675254540454 17.431641384722184 0
                            1969.25 212.216 295.673             133476 21.449 14.933    .00446608854589049  17.65564108102361 0
                             1969.5 215.988  302.01             134020 21.748 15.131   .002549333306293567   17.8900697184159 0
                            1969.75 219.744 309.998             134595 21.979  15.34  .0062118336249532575 18.093945158209088 0
                               1970 224.484  317.59             135247 22.263 15.548   .005158937127830609  18.32881970358291 0
                            1970.25 226.548 324.016             135950 22.482 15.765 -.0012578906487169987 18.528934648832834 1
                             1970.5 229.716 331.755             136676 22.633  15.96   .004631762479694784 18.690140769514365 1
                            1970.75 234.475 338.361             137456 22.835 16.196  .0015113800315272258 18.913495976160714 1
                               1971 235.828 345.307             138260 22.872 16.414 .00019116485385264805  19.03469437221988 0
                            1971.25 238.832 353.404             139034 23.111 16.631  .0019088213146701708 19.244200413348732 0
                             1971.5 240.424 361.732             139827 23.313 16.864 -.0000364782243362791 19.438904802077865 0
                            1971.75 243.595 370.843             140603 23.462 17.023   .007121127771762511 19.575752604819364 0
                               1972  247.04 381.204             141402 23.718 17.209   .006685455678039855 19.768488606337662 0
                            end
                            ------------------ copy up to and including the previous line ------------------

                            Listed 100 out of 297 observations
                            Use the count() option to list more

                            and I'm trying to predict the conditional moments for grcon2_q: the main variable in interest,
                            I have tried what you proposed and then I got the following error:
                            . ml search
                            variable __00000P not found
                            r(111);



                            Comment


                            • #15
                              Without seeing code it's hard to guess the problem, but the error message is typically given when you reference a temporary variable that does not exist at the time you reference it.

                              Please copy all your code from your do-file and paste it into your next post, surrounded by code delimiters [CODE] and [/CODE], as explained in section 12 of the Statalist FAQ linked to at the top of the page.
                              For example, the following:

                              [CODE]
                              // sample code
                              sysuse auto, clear
                              describe
                              [/CODE]

                              will be presented in the post as the following
                              Code:
                              // sample code
                              sysuse auto, clear
                              describe
                              with a monopspaced font and, crucially, with all spacing preserved as it was in your dataex output.

                              Comment

                              Working...
                              X