Announcement

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

  • Creating a Vector with Missing Data

    I am currently working on two problems:

    The first is regarding how I could convert an existing variable into a vector by each country and sector pair. I tried using the following:
    Code:
    mkmat ManShare, rownames(Industry)
    This would theoretically give me a vector which listed the proportion of manufacturing output of each industry over total output of a country in a particular year for all countries and years. However, it does not actually produce a vector since the vector has too many rows. I am trying to make a vector for each country and year pair, but am unable to do so because Stata does not allow bysort with mkmat.

    The second problem is that the vector I am trying to produce should be a 1*24 vector. However, since each country does not produce in all 24 sectors in all years, there are missing data. I am trying to include the missing data as either a zero or a missing value instead of excluding it.

    Would these be possible? Thank you very much in advance!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long Country int Time long Industry float(id4 ManShare)
    4 1996 10 1  .005093734
    4 1996  6 1  .005146236
    4 1996  9 1    .1863612
    4 1996  8 1 .0020469923
    4 1996 13 1   .15671143
    4 1996  2 1   .10667754
    4 1996 24 1           1
    4 1996 22 1  .003159164
    4 1996  3 1 .0004224119
    4 1996 12 1   .06771848
    4 1996  1 1   .42088395
    4 1997 13 2   .11123684
    4 1997 12 2  .071257584
    4 1997  1 2    .5626194
    4 1997  8 2  .002857935
    4 1997 24 2           1
    4 1997  3 2  .007754172
    4 1997  9 2    .1573661
    4 1997 10 2   .00915482
    4 1997  2 2    .0498813
    4 1997 22 2 .0004250387
    4 1998 22 3 .0035012204
    4 1998  2 3  .030519135
    4 1998  6 3   .07812565
    4 1998 24 3           1
    4 1998 12 3   .08016227
    4 1998 13 3    .1125359
    4 1998  1 3   .21774356
    4 1998  5 3   .11324187
    4 1998 10 3  .028434867
    4 1998 16 3    .0227555
    4 1998  9 3   .15857527
    4 1998  3 3   .09556854
    4 1998  7 3   .05883621
    4 1999 10 4   .05511673
    4 1999  6 4  .036008928
    4 1999 22 4    .0526593
    4 1999  1 4   .25785503
    4 1999  9 4   .11264074
    4 1999 24 4           1
    4 1999  5 4   .09235437
    4 1999  7 4    .0550415
    4 1999 12 4    .0996013
    4 1999  2 4   .02449911
    4 1999 13 4   .11118634
    4 1999  3 4    .0811204
    4 1999 16 4    .0219163
    4 2000  7 5   .04258034
    4 2000  9 5   .15333287
    4 2000 24 5           1
    4 2000 22 5   .04728615
    4 2000 13 5   .10598524
    4 2000  3 5   .11039157
    4 2000  6 5   .04661385
    4 2000  1 5    .1738673
    4 2000  5 5   .11699335
    4 2000  2 5  .031671267
    4 2000 10 5   .04822536
    4 2000 16 5  .019814735
    4 2000 12 5   .10323796
    4 2001 16 6   .08947137
    4 2001 24 6           1
    4 2001 13 6    .1505476
    4 2001 22 6    .0454179
    4 2001 10 6   .04284507
    4 2001  9 6   .09775935
    4 2001  7 6   .05812356
    4 2001  5 6   .10200913
    4 2001  1 6   .15057746
    4 2001  3 6   .09104147
    4 2001 12 6   .13022423
    4 2001  2 6    .0188323
    4 2001  6 6  .023150554
    4 2002 16 7  .012422678
    4 2002 10 7    .0654113
    4 2002 24 7           1
    4 2002  7 7    .0556372
    4 2002  5 7   .10073135
    4 2002  9 7   .09481904
    4 2002  1 7    .1900311
    4 2002  3 7   .11352996
    4 2002 13 7    .1539421
    4 2002  6 7  .021615803
    4 2002 12 7    .1403233
    4 2002 22 7   .04022419
    4 2002  2 7  .011311985
    4 2003  1 8   .18242712
    4 2003 13 8   .12135734
    4 2003  6 8  .020329406
    4 2003  2 8   .00735881
    4 2003 22 8   .04990193
    4 2003 12 8   .16217557
    4 2003 24 8           1
    4 2003 10 8   .04215821
    4 2003  5 8   .08295328
    4 2003  7 8  .031922758
    4 2003  3 8   .08527122
    4 2003  9 8    .2027528
    4 2003 16 8  .011391565
    4 2004 24 9           1
    end
    format %ty Time
    label values Country CTY1
    label def CTY1 4 "ALB", modify
    label values Industry ISIC1
    label def ISIC1 1 "15", modify
    label def ISIC1 2 "16", modify
    label def ISIC1 3 "17", modify
    label def ISIC1 5 "19", modify
    label def ISIC1 6 "20", modify
    label def ISIC1 7 "21", modify
    label def ISIC1 8 "22", modify
    label def ISIC1 9 "23", modify
    label def ISIC1 10 "24", modify
    label def ISIC1 12 "26", modify
    label def ISIC1 13 "27", modify
    label def ISIC1 16 "30", modify
    label def ISIC1 22 "36", modify
    label def ISIC1 24 "D", modify

  • #2
    The built-in Stata command -fillin-, applied to your original data set before creating matrices, would create observations representing all possible combinations of sector and country.
    Code:
    fillin country sector

    Comment

    Working...
    X