Announcement

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

  • generating lagged variables (missing values)

    I am having some trouble creating a variable with an additive string of lagged variables.

    To derive a causal effect of education spending on graduation rates it is necessary to regress on spending from all 12 years of a students education, rather than just one year. To do this I want to create new variable "gradsaid," which sums expenditures from the previous twelve years. I have 22 years of data on approximately 700 school districts for 13,825 observations.

    I have used the following command:

    tsset District year, yearly

    generate gradsaid = (STATE_AID + L.STATE_AID + L1.STATE_AID + L2.STATE_AID + L3.STATE_AID + L4.STATE_AID + L5.STATE_AID + L6.STATE_AID+ L7.STATE_AID + L8.STATE_AID + L9.STATE_AID + L10.STATE_AID + L11.STATE_AID)

    but when I run this command it generates 13,318 missing values. it generates the desired value only for year 2014 (the most recent year in my panel) with all 21 prior years missing.

    heres an interesting twist, when I try to sum over five lagged years with the following command something different happens:

    tsset District year, yearly

    generate gradsaid = (STATE_AID + L.STATE_AID + L1.STATE_AID + L2.STATE_AID + L3.STATE_AID + L4.STATE_AID)

    Now there are only 5,976 missing values generated. I now have observations of the desired value for the years 2007-2014 and 1997-2001 with the rest of the years missing.

    ive tried destringing my District, Year and STATE_AID variables with no success.

    Does anyone have a guess of what's going on?

  • #2
    Well, remember that -generate- will return a missing value if any of the terms on the right hand side are themselves missing values. So for any District and year where you do not have non-missing values of STATE_AID for the current year and all of the 11 preceding years you will get a missing result. So certainly, if you have 22 years of data, you will get only missing results for the first 11 years. You are getting missing results elsewhere, too, however. This would seem to result from the pattern of sporadic missing values in your data set.

    So the question is what to do about missing values of STATE_AID? If you want to just treat them as if they were zero, then the -tsegen- function (available from SSC) will do this. (You could also do this with -rangestat-, also available from SSC).

    If you don't want to download and learn those new commands (though I recommend you do so if you engage in this kind of thing on a recurring basis), you can also "homebrew" this solution:
    Code:
    tsset District year, yearly
    forvalues i = 1/11 {
        gen STATE_AID_L`i' = L`i'.STATE_AID
    }
    egen gradsaid = rowtotal(STATE_AID*)
    Now, this assumes that it's OK to treat missing values as zero. If that isn't suitable for your context, then you need to figure out a plan for replacing the missing values with numbers.

    Finally, if you don't actually have missing values for STATE_AID, then something else is wrong. In that case, you should post an example of your data using the -dataex- command (also available from SSC).


    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long District strL name int year double STATE_AID
      10100 "ALBANY        "     1993 16934676
      10100 "ALBANY        "     1994 18655844
      10100 "ALBANY        "     1995 21545196
      10100 "ALBANY            " 1996 20084276
      10100 "ALBANY        "     1997 23464008
      10100 "ALBANY        "     1998 26105643
      10100 "ALBANY        "     1999 32517248
      10100 "ALBANY        "     2000 38684203
      10100 "ALBANY        "     2001 40245900
      10100 "ALBANY"             2003 47527094
      10100 "ALBANY        "     2004 56037916
      10100 "ALBANY"             2005 54570126
      10100 "ALBANY"             2006 61985001
      10100 "ALBANY        "     2007 74675977
      10100 "ALBANY"             2008 88986207
      10100 "ALBANY"             2009 83680866
      10100 "ALBANY"             2010 78024625
      10100 "ALBANY"             2011 77571936
      10100 "ALBANY"             2012 78896894
      10100 "ALBANY"             2013 80293352
      10100 "ALBANY"             2014 88286815
      10201 "BERNE KNOX    "     1993  5227864
      10201 "BERNE KNOX    "     1994  5637646
      10201 "BERNE KNOX    "     1995  6155948
      10201 "BERNE KNOX        " 1996  5926168
      10201 "BERNE KNOX    "     1997  6398398
      10201 "BERNE KNOX    "     1998  6944398
      10201 "BERNE KNOX    "     1999  6948055
      10201 "BERNE KNOX    "     2000  7013455
      10201 "BERNE KNOX    "     2001  7136793
      10201 "BERNE KNOX"         2003  6886791
      10201 "BERNE KNOX    "     2004  7019225
      10201 "BERNE KNOX"         2005  7869505
      10201 "BERNE KNOX"         2006  8510365
      10201 "BERNE KNOX    "     2007  9009673
      10201 "BERNE KNOX"         2008  9494462
      10201 "BERNE KNOX"         2009  8423507
      10201 "BERNE KNOX"         2010  7824910
      10201 "BERNE KNOX"         2011  8623775
      10201 "BERNE KNOX"         2012  8204491
      10201 "BERNE KNOX"         2013  9608631
      10201 "BERNE KNOX"         2014  9342246
      10306 "BETHLEHEM     "     1993  8007761
      10306 "BETHLEHEM     "     1994  8511906
      10306 "BETHLEHEM     "     1995  8588206
      10306 "BETHLEHEM         " 1996  8952971
      10306 "BETHLEHEM     "     1997  9859974
      10306 "BETHLEHEM     "     1998 10556709
      10306 "BETHLEHEM     "     1999 11309114
      10306 "BETHLEHEM     "     2000 11770733
      10306 "BETHLEHEM     "     2001 12547654
      10306 "BETHLEHEM"          2003 14252549
      10306 "BETHLEHEM     "     2004 14914892
      10306 "BETHLEHEM"          2005 15751718
      10306 "BETHLEHEM"          2006 23148376
      10306 "BETHLEHEM     "     2007 22630159
      10306 "BETHLEHEM"          2008 26082048
      10306 "BETHLEHEM"          2009 25788559
      10306 "BETHLEHEM"          2010 24368223
      10306 "BETHLEHEM"          2011 22747959
      10306 "BETHLEHEM"          2012 23180216
      10306 "BETHLEHEM"          2013 23082869
      10306 "BETHLEHEM"          2014 23832274
      10402 "RAVENA COEYMAN"     1993  8974685
      10402 "RAVENA COEYMAN"     1994  9497632
      10402 "RAVENA COEYMAN"     1995  9684818
      10402 "RAVENA COEYMANS   " 1996  9728908
      10402 "RAVENA COEYMAN"     1997 10096998
      10402 "RAVENA COEYMAN"     1998 10681997
      10402 "RAVENA COEYMAN"     1999 11442665
      10402 "RAVENA COEYMAN"     2000 12295390
      10402 "RAVENA COEYMAN"     2001 12620889
      10402 "RAVENA COEYMAN"     2003 13823812
      10402 "RAVENA COEYMAN"     2004 15042309
      10402 "RAVENACOEYMAN"      2005 14993555
      10402 "RAVENACOEYMAN"      2006 15856148
      10402 "RAVENA COEYMAN"     2007 16799855
      10402 "RAVENACOEYMAN"      2008 16957149
      10402 "RAVENACOEYMAN"      2009 16344261
      10402 "RAVENACOEYMAN"      2010 15579531
      10402 "RAVENACOEYMAN"      2011 15130256
      10402 "RAVENACOEYMAN"      2012 14806715
      10402 "RAVENA COEYMAN"     2013 15469119
      10402 "RAVENA COEYMAN"     2014 15868267
      10500 "COHOES        "     1993 10100539
      10500 "COHOES        "     1994 11419104
      10500 "COHOES        "     1995 10517848
      10500 "COHOES            " 1996  9762318
      10500 "COHOES        "     1997  9830637
      10500 "COHOES        "     1998 12734035
      10500 "COHOES        "     1999 13537636
      10500 "COHOES        "     2000 15435786
      10500 "COHOES        "     2001 15037230
      10500 "COHOES"             2003 14073116
      10500 "COHOES        "     2004 14374800
      10500 "COHOES"             2005 15126287
      10500 "COHOES"             2006 15970615
      10500 "COHOES        "     2007 18954832
      10500 "COHOES"             2008 20292219
      10500 "COHOES"             2009 19755562
      end
      format %ty year
      ------------------ copy up to and including the previous line ------------------

      Comment


      • #4
        So it's as I suspected in #2. You have no observations for year 2002. So for any year where 2002 would be among the 12 years you are trying to add up, you get missing values.

        If you want to just ignore 2002 (i.e. treat 2002 as if STATE_AID = 0), my suggestions in #2 all work. If not, you need to get, or impute, values for 2002.

        Comment


        • #5
          nice catch. thank you very much

          Comment


          • #6
            Cross-posted at http://stackoverflow.com/questions/4...missing-values

            Please note our cross-posting policy, which is that you should tell us about it. http://www.statalist.org/forums/help#crossposting

            Comment


            • #7
              Originally posted by Nick Cox View Post
              Cross-posted at http://stackoverflow.com/questions/4...missing-values

              Please note our cross-posting policy, which is that you should tell us about it. http://www.statalist.org/forums/help#crossposting
              Will do in the future. Thanks.

              Comment


              • #8
                Dear statalist
                I am working on a panel data set and i need to create some lagged variables.
                However, when i try doing this in stata 14 using the code: gen lrainfall = l.rainfall, i get missing values for all my observations. I am worried because the are no missing values for my original variables.
                What is happening?
                Can someone help?

                Comment


                • #9
                  #8 is a duplicate post, asked and answered at https://www.statalist.org/forums/for...variableshttps. Martin, please do not do that. Post your question once and wait for a response. If you do not get one after several hours, especially if, as is the case here, your post was placed at a time of day when the list is usually very active, then it probably means that your question is vague, poorly worded, or otherwise not answerable. In that case, reposting after several hours is appropriate, but you should modify the question in line with the excellent advice provided in the FAQ about how to post clear, focused questions that have a high probability of drawing a helpful and timely response.

                  Comment


                  • #10
                    Hello Stata.
                    after going through the thread and trying every possible given solution, I still get 100% missing values for lag1, lag2 and lag3 commands.
                    precisely I first xtset my data as
                    Code:
                    mi xtset pan_var year
                    "mi-xtset" because i had miset my data and after using all sorts of mi-unset data, I failed.
                    second i sorted my data using
                    Code:
                    sort pan_var year
                    third, after sorting, i lagged the dependent variable using
                    Code:
                    by pan_var: gen dis_depth_lag1 = L1.dis_depth
                    and i get 100% missing data.
                    i retried with L2 and L3, i still get 100% missing values.
                    my dataset example is
                    Code:
                    input float year str40(iso3_o iso3_d) int dis_depth
                    2000 "AUS" "ALB" 0
                    2001 "AUS" "ALB" 0
                    2002 "AUS" "ALB" 0
                    2003 "AUS" "ALB" 0
                    2004 "AUS" "ALB" 0
                    2005 "AUS" "ALB" 0
                    2006 "AUS" "ALB" 0
                    2007 "AUS" "ALB" 0
                    2008 "AUS" "ALB" 0
                    2009 "AUS" "ALB" 0
                    2010 "AUS" "ALB" 0
                    2011 "AUS" "ALB" 0
                    2012 "AUS" "ALB" 0
                    2013 "AUS" "ALB" 0
                    2014 "AUS" "ALB" 0
                    2015 "AUS" "ALB" 0
                    2016 "AUS" "ALB" 0
                    2017 "AUS" "ALB" 0
                    2018 "AUS" "ALB" 0
                    2019 "AUS" "ALB" 0
                    2020 "AUS" "ALB" 0
                    2021 "AUS" "ALB" 0
                    2022 "AUS" "ALB" 0
                    2000 "AUT" "ALB" 0
                    2001 "AUT" "ALB" 0
                    2002 "AUT" "ALB" 0
                    2003 "AUT" "ALB" 0
                    2004 "AUT" "ALB" 0
                    2005 "AUT" "ALB" 0
                    2006 "AUT" "ALB" 0
                    2007 "AUT" "ALB" 0
                    2008 "AUT" "ALB" 0
                    2009 "AUT" "ALB" 0
                    2010 "AUT" "ALB" 0
                    2011 "AUT" "ALB" 0
                    2012 "AUT" "ALB" 0
                    2013 "AUT" "ALB" 0
                    2014 "AUT" "ALB" 0
                    2015 "AUT" "ALB" 0
                    2016 "AUT" "ALB" 0
                    2017 "AUT" "ALB" 0
                    2018 "AUT" "ALB" 0
                    2019 "AUT" "ALB" 0
                    2020 "AUT" "ALB" 0
                    2021 "AUT" "ALB" 0
                    2022 "AUT" "ALB" 0
                    2000 "BEL" "ALB" 0
                    2001 "BEL" "ALB" 0
                    2002 "BEL" "ALB" 0
                    2003 "BEL" "ALB" 0
                    2004 "BEL" "ALB" 0
                    2005 "BEL" "ALB" 0
                    2006 "BEL" "ALB" 0
                    2007 "BEL" "ALB" 0
                    2008 "BEL" "ALB" 0
                    2009 "BEL" "ALB" 0
                    2010 "BEL" "ALB" 0
                    2011 "BEL" "ALB" 0
                    2012 "BEL" "ALB" 0
                    2013 "BEL" "ALB" 0
                    2014 "BEL" "ALB" 0
                    2015 "BEL" "ALB" 0
                    2016 "BEL" "ALB" 0
                    2017 "BEL" "ALB" 0
                    2018 "BEL" "ALB" 0
                    2019 "BEL" "ALB" 0
                    2020 "BEL" "ALB" 0
                    2021 "BEL" "ALB" 0
                    2022 "BEL" "ALB" 0
                    2000 "BGR" "ALB" 0
                    2001 "BGR" "ALB" 0
                    2002 "BGR" "ALB" 0
                    2003 "BGR" "ALB" 0
                    2004 "BGR" "ALB" 0
                    2005 "BGR" "ALB" 0
                    2006 "BGR" "ALB" 0
                    2007 "BGR" "ALB" 0
                    2008 "BGR" "ALB" 0
                    2009 "BGR" "ALB" 0
                    2010 "BGR" "ALB" 0
                    2011 "BGR" "ALB" 0
                    2012 "BGR" "ALB" 0
                    2013 "BGR" "ALB" 0
                    2014 "BGR" "ALB" 0
                    2015 "BGR" "ALB" 0
                    2016 "BGR" "ALB" 0
                    2017 "BGR" "ALB" 0
                    2018 "BGR" "ALB" 0
                    2019 "BGR" "ALB" 0
                    2020 "BGR" "ALB" 0
                    2021 "BGR" "ALB" 0
                    2022 "BGR" "ALB" 0
                    2000 "CAN" "ALB" 0
                    2001 "CAN" "ALB" 0
                    2002 "CAN" "ALB" 0
                    2003 "CAN" "ALB" 0
                    2004 "CAN" "ALB" 0
                    2005 "CAN" "ALB" 0
                    2006 "CAN" "ALB" 0
                    2007 "CAN" "ALB" 0
                    end
                    in essence, the dataset ranges from 1995-2022, dataex gives sample from 2000 because the panel is unbalanced and for country ALB the data range starts from 2000-2022.
                    note: dis_depth is a factor variable with values ranging from 0 to 7.
                    dependent variable has no missing values but contains Zeroes.
                    kindly, help me solve this issue.
                    Last edited by Dr. Iqra Yaseen; 08 Feb 2024, 03:47.

                    Comment


                    • #11
                      To create the lagged values, you do not need to specify -by pan_var:-. Just -gen dis_depth_lag1 = L1.dis_depth- will do it. In ordinary data sets, there is no harm in using the -by- prefix for this. But I think in your multiply imputed data, there is. The problem, I believe, arises from sorting on the pan_var. Depending on how you originally -mi set- your data, it may need to be sorted first on imputation number. When you -sort pan_var-, you scramble that and Stata may be having trouble finding the right observations for the labs with the data not sorted by imputation number. (Since you, appropriately, -mi xtset- your data, Stata is probably looking for the imputation number first.) So I'm suggesting you drop the -sort- command and drop the -by pan_var:- prefix.

                      Finally, another thought. Why not generate the lagged variable in the original data before you -mi set- it?

                      Comment


                      • #12
                        thank you for your response, Clyde Schechter.
                        i shall make all points clear
                        1. even by using simple gen dis_depth_lag1 = L1.dis_depth, i still get the same 100% missing values result.
                        2. i had mi-set my data in my elementary years of research (phd) to tackle missing values. when i didn't get the requisite results for missing data i simply dropped the imputation numbers out of ignorance and unawareness about mi-unset command. later when i tried to mi-unset my data, i failed by all means. so, at the end i can't mi-unset the data neither i have the imputation numbers.
                        3. even by dropping the sort and by pan_var command, i still get the same results.
                        4. if i can't log my IV by any means, is there any alternative to account for reverse causality of my DV with IV. in essence, i need to log the IV to account for reverse causality as the issue has been raised by one of the reviewers of my paper.
                        5. i am employing ppmlhdfe model in my paper where i am accounting for endogeneity, heteroscedasticity and other biases by using country specific and country pair fixed effects. at the backdrop of this model, if i don't need to account for the reverse causality of my variable of interest, can you give me some references for the same that i can cite in my paper.
                        i hope these questions doesn't take much of your and other experts' time.
                        thank you so much.

                        Comment


                        • #13
                          If I understand #12 correctly, the data set you are working with was original -mi set-, but then was stripped of the _mi variables that enumerate the imputations, and those cannot be recovered. But, then I don't see how you could have (recently) -mi xtset- the data, because that command, too, needs the _mi variables. So this is all very confusing. I think you need to run -dataex- to show example data, and be sure to include any variables whose names begin with _ in the example. Also, run the command -char dir- and post the output that Stata gives you. (I know you showed some example data in #10, but it does not include the necessary variables.) If you can provide a better example, I will try to figure out some way to salvage the situation.

                          As for your question 5, I am not the right person to do this. I don't work in economics or finance and I'm in no position to judge causality in trade data. For that you need advice for somebody with expertise in that area--it's not a statistical issue, it's an economics issue. You probablyl can get that advice here on Statalist: we have plenty of economists, including some who specialize in trade, who post here frequently. But to attract their attention, you should start a new thread that asks only that question, and give the thread a title that clearly and succinctly describes this issue.

                          Comment


                          • #14
                            1. regarding mi-xtset command, it works well and gives me the following output
                            Code:
                             mi xtset pan_var year
                                   panel variable:  pan_var (weakly balanced)
                                    time variable:  year, 1995 to 2022
                                            delta:  1 unit
                            2. regarding dataex example with _
                            Code:
                            input float year str40(iso3_o iso3_d) double tradeflow_imf_d byte dis_dum int dis_depth float(ln_pop_o ln_pop_d ln_gdp_d ln_gdp_o) byte(rta contig comlang_off comcol heg_o heg_d)
                            1995 "ARE" "ARG"                  18 0 0  7.760597 10.458325 19.560337 18.001274 0 0 0 0 0 0
                            1995 "ARE" "ATG"                   0 0 0  7.760597  4.224627 13.110665 18.001274 0 0 0 1 0 0
                            1995 "ARE" "BHR"                 111 0 0  7.760597  6.334575 15.581861 18.001274 1 0 1 1 0 0
                            1995 "ARE" "BRA"  107.00000000000003 0 0  7.760597 11.994678  20.46054 18.001274 0 0 0 0 0 0
                            1995 "ARE" "BRB"                   0 0 0  7.760597  5.572781 14.631746 18.001274 0 0 0 1 0 0
                            1995 "ARE" "BRN"                7600 0 0  7.760597  5.686985 15.370285 18.001274 0 0 0 1 0 0
                            1995 "ARE" "BWA"                   0 0 0  7.760597  7.367363 15.369562 18.001274 0 0 0 1 0 0
                            1995 "ARE" "CHL"   44.99999999999999 0 0  7.760597  9.577765 18.083097 18.001274 0 0 0 0 0 0
                            1995 "ARE" "CHN"  1645.9999999999993 0 0  7.760597  14.00187  20.40582 18.001274 0 0 0 0 0 0
                            1995 "ARE" "COL"     909.31201171875 0 0  7.760597  10.50709 18.342798 18.001274 0 0 0 0 0 0
                            1995 "ARE" "CRI"   .9999999999999996 0 0  7.760597  8.154269 16.277008 18.001274 0 0 0 0 0 0
                            1995 "ARE" "CUB"                   0 0 0  7.760597  9.299451 17.230894 18.001274 0 0 0 0 0 0
                            1995 "ARE" "DMA"   8.208000183105469 0 0  7.760597 4.2678356 12.319567 18.001274 0 0 0 1 0 0
                            1995 "ARE" "DOM"                   0 0 0  7.760597  8.984439 16.610258 18.001274 0 0 0 0 0 0
                            1995 "ARE" "ECU"                   4 0 0  7.760597  9.333955  17.01142 18.001274 0 0 0 0 0 0
                            1995 "ARE" "GAB"                   0 0 0  7.760597  6.985158  22.32444 18.001274 0 0 0 0 0 0
                            1995 "ARE" "GRD" .024000000208616257 0 0  7.760597  4.607697  12.52923 18.001274 0 0 0 1 0 0
                            1995 "ARE" "GUY"                   0 0 0  7.760597  6.590488 13.340096 18.001274 0 0 0 1 0 0
                            1995 "ARE" "HKG"  197.99999999999991 0 0  7.760597  8.725199 18.789848 18.001274 0 0 0 1 0 0
                            1995 "ARE" "KAZ"   .9999999999999996 0 0  7.760597  9.668754 16.829784 18.001274 0 0 0 0 0 0
                            1995 "ARE" "KNA"                   0 0 0  7.760597  3.758592  12.34905 18.001274 0 0 0 1 0 0
                            1995 "ARE" "KWT"                  55 0 0  7.760597  7.369048 17.118422 18.001274 1 0 1 1 0 0
                            1995 "ARE" "LCA"   .5460000038146973 0 0  7.760597  4.990705  13.23714 18.001274 0 0 0 1 0 0
                            1995 "ARE" "MAC"  110.18599700927734 0 0  7.760597  5.987605 15.696604 18.001274 0 0 0 0 0 0
                            1995 "ARE" "MDV"     19810.365234375 0 0  7.760597  5.501115  12.89669 18.001274 0 0 0 1 0 0
                            1995 "ARE" "MEX"                  25 0 0  7.760597 11.465756  19.65555 18.001274 0 0 0 0 0 0
                            1995 "ARE" "MUS"                   0 0 0  7.760597  7.023275  15.21184 18.001274 0 0 0 1 0 0
                            1995 "ARE" "MYS"                 373 0 0  7.760597  9.939114 18.302263 18.001274 0 0 0 1 0 0
                            1995 "ARE" "OMN"   .9999999999999996 0 0  7.760597   7.67536 16.440367 18.001274 1 1 1 0 0 0
                            1995 "ARE" "PAN"                   0 0 0  7.760597    7.9219 15.883145 18.001274 0 0 0 0 0 0
                            1995 "ARE" "PER"   .9999999999999996 0 0  7.760597 10.083275 17.767672 18.001274 0 0 0 0 0 0
                            1995 "ARE" "QAT"                 151 0 0  7.760597  6.216913 15.912045 18.001274 1 1 1 1 0 0
                            1995 "ARE" "SAU"   750.9999999999995 0 0  7.760597   9.82916 18.774555 18.001274 1 1 1 0 0 0
                            1995 "ARE" "SGP"                 211 0 0  7.760597  8.167494 18.291615 18.001274 0 0 0 1 0 0
                            1995 "ARE" "SUR"                   0 0 0  7.760597  6.077128 13.450185 18.001274 0 0 0 0 0 0
                            1995 "ARE" "SYC"    1343.97998046875 0 0  7.760597  4.321533 13.138657 18.001274 0 0 0 1 0 0
                            1995 "ARE" "THA"   441.0000000000002 0 0  7.760597  10.98502 18.939585 18.001274 0 0 0 0 0 0
                            1995 "ARE" "TTO"   22.19300079345703 0 0  7.760597  7.134892 15.488714 18.001274 0 0 0 1 0 0
                            1995 "ARE" "TUR"  199.00000000000006 0 0  7.760597 10.977163  18.94828 18.001274 0 0 0 0 0 0
                            1995 "ARE" "URY"  3.0000000000000013 0 0  7.760597  8.078497 16.775494 18.001274 0 0 0 0 0 0
                            1995 "ARE" "VCT"                   0 0 0  7.760597 4.6832604  12.49306 18.001274 0 0 0 1 0 0
                            1995 "ARG" "ARE"               18000 0 0 10.458325  7.760597 18.001274 19.560337 0 0 0 0 0 0
                            1995 "ARG" "ATG"                   0 0 0 10.458325  4.224627 13.110665 19.560337 0 0 0 0 0 0
                            1995 "ARG" "BHR"   456.5190124511719 0 0 10.458325  6.334575 15.581861 19.560337 0 0 0 0 0 0
                            1995 "ARG" "BRA"             6127277 0 0 10.458325 11.994678  20.46054 19.560337 1 1 0 0 0 0
                            1995 "ARG" "BRB"  1009.9669799804688 0 0 10.458325  5.572781 14.631746 19.560337 0 0 0 0 0 0
                            1995 "ARG" "BRN"                   0 0 0 10.458325  5.686985 15.370285 19.560337 0 0 0 0 0 0
                            1995 "ARG" "BWA"                   0 0 0 10.458325  7.367363 15.369562 19.560337 0 0 0 0 0 0
                            1995 "ARG" "CHL"             1384500 0 0 10.458325  9.577765 18.083097 19.560337 1 1 1 0 0 0
                            1995 "ARG" "CHN"              370397 0 0 10.458325  14.00187  20.40582 19.560337 0 0 0 0 0 0
                            1995 "ARG" "COL"        147518.34375 0 0 10.458325  10.50709 18.342798 19.560337 1 0 1 0 0 0
                            1995 "ARG" "CRI"       27102.0234375 0 0 10.458325  8.154269 16.277008 19.560337 0 0 1 0 0 0
                            1995 "ARG" "CUB"       71592.3984375 0 0 10.458325  9.299451 17.230894 19.560337 1 0 1 0 0 0
                            1995 "ARG" "DMA"  15.187000274658203 0 0 10.458325 4.2678356 12.319567 19.560337 0 0 0 0 0 0
                            1995 "ARG" "DOM"                   0 0 0 10.458325  8.984439 16.610258 19.560337 0 0 1 0 0 0
                            1995 "ARG" "ECU"         75695.90625 0 0 10.458325  9.333955  17.01142 19.560337 1 0 1 0 0 0
                            1995 "ARG" "GAB"                   0 0 0 10.458325  6.985158  22.32444 19.560337 0 0 0 0 0 0
                            1995 "ARG" "GRD"  204.83900451660156 0 0 10.458325  4.607697  12.52923 19.560337 0 0 0 0 0 0
                            1995 "ARG" "GUY"                   0 0 0 10.458325  6.590488 13.340096 19.560337 1 0 0 0 0 0
                            1995 "ARG" "HKG"          295746.375 0 0 10.458325  8.725199 18.789848 19.560337 0 0 0 0 0 0
                            1995 "ARG" "KAZ"                .048 0 0 10.458325  9.668754 16.829784 19.560337 0 0 0 0 0 0
                            1995 "ARG" "KNA"                   0 0 0 10.458325  3.758592  12.34905 19.560337 0 0 0 0 0 0
                            1995 "ARG" "KWT"    15251.1103515625 0 0 10.458325  7.369048 17.118422 19.560337 0 0 0 0 0 0
                            1995 "ARG" "LCA"  397.72601318359375 0 0 10.458325  4.990705  13.23714 19.560337 0 0 0 0 0 0
                            1995 "ARG" "MAC"   243.6060028076172 0 0 10.458325  5.987605 15.696604 19.560337 0 0 0 0 0 0
                            1995 "ARG" "MDV"   31.83300018310547 0 0 10.458325  5.501115  12.89669 19.560337 0 0 0 0 0 0
                            1995 "ARG" "MEX"            209775.5 0 0 10.458325 11.465756  19.65555 19.560337 1 0 1 0 0 0
                            1995 "ARG" "MUS"         16449.71875 0 0 10.458325  7.023275  15.21184 19.560337 0 0 0 0 0 0
                            1995 "ARG" "MYS"       257245.734375 0 0 10.458325  9.939114 18.302263 19.560337 1 0 0 0 0 0
                            1995 "ARG" "OMN"     17255.419921875 0 0 10.458325   7.67536 16.440367 19.560337 0 0 0 0 0 0
                            1995 "ARG" "PAN"    12198.1650390625 0 0 10.458325    7.9219 15.883145 19.560337 0 0 1 0 0 0
                            1995 "ARG" "PER"            346681.5 0 0 10.458325 10.083275 17.767672 19.560337 1 0 1 0 0 0
                            1995 "ARG" "QAT"   2197.802001953125 0 0 10.458325  6.216913 15.912045 19.560337 0 0 0 0 0 0
                            1995 "ARG" "SAU"       43243.5234375 0 0 10.458325   9.82916 18.774555 19.560337 0 0 0 0 0 0
                            1995 "ARG" "SGP"       86742.0390625 0 0 10.458325  8.167494 18.291615 19.560337 1 0 0 0 0 0
                            1995 "ARG" "SUR"   109.8010025024414 0 0 10.458325  6.077128 13.450185 19.560337 0 0 0 0 0 0
                            1995 "ARG" "SYC"                   0 0 0 10.458325  4.321533 13.138657 19.560337 0 0 0 0 0 0
                            1995 "ARG" "THA"       172556.203125 0 0 10.458325  10.98502 18.939585 19.560337 1 0 0 0 0 0
                            1995 "ARG" "TTO"    3287.77197265625 0 0 10.458325  7.134892 15.488714 19.560337 1 0 0 0 0 0
                            1995 "ARG" "TUR"       208616.984375 0 0 10.458325 10.977163  18.94828 19.560337 0 0 0 0 0 0
                            1995 "ARG" "URY"         608636.0625 0 0 10.458325  8.078497 16.775494 19.560337 1 1 1 0 0 0
                            1995 "ARG" "VCT"   243.1020050048828 0 0 10.458325 4.6832604  12.49306 19.560337 0 0 0 0 0 0
                            1995 "ATG" "ARE"                   0 0 0  4.224627  7.760597 18.001274 13.110665 0 0 0 1 0 0
                            1995 "ATG" "ARG"                   0 0 0  4.224627 10.458325 19.560337 13.110665 0 0 0 0 0 0
                            1995 "ATG" "BHR"                   0 0 0  4.224627  6.334575 15.581861 13.110665 0 0 0 1 0 0
                            1995 "ATG" "BRA"                   0 0 0  4.224627 11.994678  20.46054 13.110665 0 0 0 0 0 0
                            1995 "ATG" "BRB"                   0 0 0  4.224627  5.572781 14.631746 13.110665 1 0 1 1 0 0
                            1995 "ATG" "BRN"                   0 0 0  4.224627  5.686985 15.370285 13.110665 0 0 0 1 0 0
                            1995 "ATG" "BWA"                   0 0 0  4.224627  7.367363 15.369562 13.110665 0 0 1 1 0 0
                            1995 "ATG" "CHL"                   0 0 0  4.224627  9.577765 18.083097 13.110665 0 0 0 0 0 0
                            1995 "ATG" "CHN"                   0 0 0  4.224627  14.00187  20.40582 13.110665 0 0 0 0 0 0
                            1995 "ATG" "COL"                   0 0 0  4.224627  10.50709 18.342798 13.110665 0 0 0 0 0 0
                            1995 "ATG" "CRI"                   0 0 0  4.224627  8.154269 16.277008 13.110665 0 0 0 0 0 0
                            1995 "ATG" "CUB"                   0 0 0  4.224627  9.299451 17.230894 13.110665 0 0 0 0 0 0
                            1995 "ATG" "DMA"                   0 0 0  4.224627 4.2678356 12.319567 13.110665 1 0 1 1 0 0
                            1995 "ATG" "DOM"                   0 0 0  4.224627  8.984439 16.610258 13.110665 0 0 0 0 0 0
                            1995 "ATG" "ECU"                   0 0 0  4.224627  9.333955  17.01142 13.110665 0 0 0 0 0 0
                            1995 "ATG" "GAB"                   0 0 0  4.224627  6.985158  22.32444 13.110665 0 0 0 0 0 0
                            1995 "ATG" "GRD"                   0 0 0  4.224627  4.607697  12.52923 13.110665 1 0 1 1 0 0
                            1995 "ATG" "GUY"                   0 0 0  4.224627  6.590488 13.340096 13.110665 1 0 1 1 0 0
                            end
                            3. regarding char dir command
                            Code:
                            Listed 100 out of 96010 observations
                            Use the count() option to list more
                            
                            . char dir
                              _dta[iis]:                  pan_var
                              _dta[tis]:                  year
                              _dta[_TSitrvl]:             1
                              _dta[_TSdelta]:             +1.0000000000000X+000
                              _dta[_TSpanel]:             pan_var
                              _dta[_TStvar]:              year
                              _dta[note7]:                All interaction terms are from centered component variables
                              _dta[note6]:                For c variable, pre-1973 values are set 1973 value if missing
                              _dta[note5]:                Exceptions to averaging deaths over conflict years include Rwanda and Nagorno Karaba..
                              _dta[note4]:                wbgdp gives federal republic data for Germany. unclear if Czech data refers to Czech..
                              _dta[note3]:                dropped Germany (ccode = 255) for lack of data, added missing cases for Czechoslovak..
                              _dta[note2]:                Interstate, CIVIL and extrastate wars, by nation year, when multiple wars then only ..
                              _dta[note1]:                gdpppp95 data for Bosnia/Herzegovina; Bhutan; Brunei; */
                              _dta[__xi__Vars__Prefix__]: _I _I _I _I _I _I
                              _dta[__xi__Vars__To__Drop__]:
                                                          _Icontnt1_2 _Icontnt1_3 _Icontnt1_4 _Icontnt1_5 _Icontnt1_6 _Icontnt1_7
                              _dta[st_ver]:               2
                              _dta[st_bt]:                dur8099
                              _dta[st_bd]:                failure
                              _dta[st_o]:                 0
                              _dta[st_s]:                 1
                              _dta[st_bs]:                1
                              _dta[_lang_c]:              default
                              _dta[_lang_list]:           default
                              _dta[st_t]:                 tenplus
                              _dta[st_t0]:                time0
                              _dta[st_d]:                 leadgone
                              _dta[st_id]:                leadnew
                              _dta[_dta]:                 st
                              _dta[__JVarLab]:            Indicator Name
                              _dta[dbf_year]:             120
                              _dta[dbf_month]:            8
                              _dta[dbf_day]:              19
                              _dta[dbf_version]:          3
                              _dta[sp__ver]:              1
                              _dta[sp__ID]:               _ID
                              _dta[sp__ID_var]:           _ID
                              _dta[sp__coord_sys]:        planar
                              _dta[sp__CX]:               _CX
                              _dta[sp__CY]:               _CY
                              _dta[sp__shp_dta]:          WorldCountries_shp.dta
                              _dta[_mi_style]:            mlong
                              _dta[_mi_M]:                0
                              _dta[_mi_N]:                47106
                              _dta[_mi_marker]:           _mi_ds_1
                              _dta[_mi_ivars]:            tradeflow_imf_o tradeflow_imf_d agree_cu gdp_d gdp_o polity_d polity_o
                              _dta[_mi_n]:                20840
                              _dta[_mi_rvars]:            disputes outcome rta
                              _dta[_mi_update]:           1262307314
                              _dta[ReS_Xij_n]:            1
                              _dta[ReS_Xij_long1]:        yr
                              _dta[ReS_Xij_wide1]:        yr1995 yr1996 yr1997 yr1998 yr1999 yr2000 yr2001 yr2002 yr2003 yr2004 yr2005 yr2006 ..
                              _dta[ReS_Xij]:              yr
                              _dta[ReS_str]:              0
                              _dta[ReS_j]:                year
                              _dta[ReS_ver]:              v.2
                              _dta[ReS_i]:                id
                              _dta[note0]:                7
                              year[destring]:             Characters removed were:
                              year[destring_cmd]:         destring year, replace
                              iso3_o[_de_col_width_]:                        16
                              iso3_d[_de_col_width_]:                        21
                              tradeflow_~d[destring]:     Characters removed were:
                              tradeflow_~d[destring_cmd]: destring tradeflow_imf_d, replace force
                              pop_o[destring]:            Characters removed were:
                              pop_o[destring_cmd]:        destring pop, replace ignore(",")
                              pop_d[destring]:            Characters removed were:
                              pop_d[destring_cmd]:        destring pop, replace ignore(",")
                              gdp_o[destring]:            Characters removed were:
                              gdp_o[destring_cmd]:        destring gdp, replace
                              gdp_d[destring]:            Characters removed were:
                              gdp_d[destring_cmd]:        destring gdp, replace
                            thank you for your time and attention.

                            Comment


                            • #15
                              Thank you. Somethings have been clarified, and some are a bit more mysterious.

                              In the example data you show, you did not include pan_var, so I can't try to replicate your -mi xtset- command. I am guessing that the panel variable is actually created by -egen pan_var = group(iso3*)- or something equivalent. Be that as it may, your example data also includes data from only a single year, 1995, so the lagged values will, of course, all be missing in this situation. Are you sure your full data set has multi-year data? Can you post a data example that includes the panel variable, contains multi-year data, and reproduces your problem of getting all missing values for the lag variables? When I used your example data from #10 and ran
                              Code:
                              egen pan_var = group(iso3*), label
                              xtset pan_var year
                              
                              gen lag_dis_depth = L1.dis_depth
                              the lagged variable is appropriately created, and the only missing values are in the first observation of each pan_var group, as should be the case.


                              I notice that characteristic _dta[_mi_M] is 0. From that I infer that even though you have -mi set- your data, you have not actually done any imputations yet. This makes it even harder to understand why you are having the problem you have. I had thought that perhaps after running multiple imputations that the extra imputed observations were getting in the way some how, but now I see that there aren't even any imputations to interfere in the calculation. So the cause of your problem seems even more elusive than before.

                              Comment

                              Working...
                              X