Announcement

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

  • Matching firms based on several criteria

    Hello Stata community,

    I have a panel dataset consisting of many firms over 22 years. Firms are identified by "DSCD" and each belongs to an Industry " ffi ". Each firm has an observation for a variable " RDTAwt " that is either 0 or >0. I have created an indicator variable "balancedind" that =1 where all data required to run regressions is available in that firm-year. I am interested in firms that have an "RDTAwt" observation that is >0. I would like to match for each of these firm years where RDTAwt > 0, a matched firm where RDTAwt = 0, conditioned on balancedind ==1 for both firms. I would like to match based on the industry " ffi " and firm size, "TA". I require an exact match on ffi (industry) and a match within 20% for TA (size). For example, if a firm has TA of 100 then a matched firm can have 80 <= TA <= 120. I am also wondering if there is a way I can switch between matching with and without replacement so that I can compare the results with both.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long DSCD int year float(balancedind RDTAwt) double TA float ffi
    1 1999 .          0   178392 36
    1 2000 .          0   279960 36
    1 2001 .          0   376506 36
    1 2002 .          0   460890 36
    1 2003 .          0   515080 36
    1 2004 .          0   592146 36
    1 2005 .          0   704957 36
    1 2006 .          0   900030 36
    1 2007 .          0  1028851 36
    1 2008 .          0  1798857 36
    1 2009 .          0  1754039 36
    1 2010 .          0  1716317 36
    1 2011 . .004691441  1708051 36
    1 2012 . .013918202  1727560 36
    1 2013 .  .02107018  1677374 36
    1 2014 . .027589554  2103174 36
    1 2020 .          0        . 36
    1 2021 .          0        .  .
    1 2015 1 .029417917  1979222 36
    1 2016 1 .034052774  2004894 36
    1 2017 1  .03758303  2073407 36
    1 2018 1  .03764191  2005064 36
    1 2019 1  .03967754  2116877 36
    2 1999 1          0  1742574 17
    2 2000 .          0  1841439 17
    2 2021 .          0        .  .
    2 2001 1          0  2224580 17
    2 2002 1          0  2258530 17
    2 2003 1          0  2330093 17
    2 2004 1          0  2355852 17
    2 2005 1          0  2433316 17
    2 2006 1          0  2506421 17
    2 2007 1          0  2683805 17
    2 2008 1          0  3032502 17
    2 2009 1          0  3239283 17
    2 2010 1          0  3074743 17
    2 2011 1          0  3147822 17
    2 2012 1          0  3160926 17
    2 2013 1          0  3259826 17
    2 2014 1          0  7464392 17
    2 2015 1          0  6961732 17
    2 2016 1          0  7300905 17
    2 2017 1          0  8992511 17
    2 2018 1          0  9551419 17
    2 2019 1          0 10131600 17
    2 2020 1          0 10580800 17
    3 1999 1          0    80216 21
    3 2000 .          0    54030 21
    3 2009 .          0        . 21
    3 2010 .          0        . 21
    3 2011 .          0        . 21
    3 2012 .          0        . 21
    3 2013 .          0        . 21
    3 2014 .          0        . 21
    3 2015 .          0        . 21
    3 2016 .          0        . 21
    3 2017 .          0        . 21
    3 2018 .          0        . 21
    3 2019 .          0        . 21
    3 2020 .          0        . 21
    3 2021 .          0        .  .
    3 2001 1          0    38279 21
    3 2002 1          0    36002 21
    3 2003 1          0    30346 21
    3 2004 1          0    26626 21
    3 2005 1          0    26354 21
    3 2006 1          0    27188 21
    3 2007 1          0    29300 21
    3 2008 1          0    21030 21
    4 1999 .          0  2280227 24
    4 2000 .          0  2162274 24
    4 2001 .          0  2025012 24
    4 2002 .          0  1887196 24
    4 2003 .          0  1838680 24
    4 2004 .          0  1933886 24
    4 2005 .          0  1839100 24
    4 2006 .          0  1962882 24
    4 2007 .          0  2079041 24
    4 2008 .          0  2090531 24
    4 2009 .          0  2252931 24
    4 2010 .          0  2363653 24
    4 2011 .          0  2569348 24
    4 2012 .          0  3122951 24
    4 2013 .          0  3685501 24
    4 2014 .          0  2453115 24
    4 2021 .          0        .  .
    4 2015 1          0  2319263 24
    4 2016 1          0  2685760 24
    4 2017 1          0  2858481 24
    4 2018 1          0  2780666 24
    4 2019 1          0  2860996 24
    4 2020 1          0  3728733 24
    5 1999 .          0        .  .
    5 2000 .          0        .  .
    5 2001 .          0        .  .
    5 2002 .          0        .  .
    5 2003 .          0        .  .
    5 2004 .          0        .  .
    5 2005 .          0        .  .
    5 2006 .          0        .  .
    end
    label values DSCD DSCD1
    label def DSCD1 1 "130042", modify
    label def DSCD1 2 "130062", modify
    label def DSCD1 3 "130079", modify
    label def DSCD1 4 "130086", modify
    label def DSCD1 5 "130088", modify
    label values ffi ffi
    label def ffi 17 "Construction Materials", modify
    label def ffi 21 "Machinery", modify
    label def ffi 24 "Aircraft", modify
    label def ffi 36 "Electronic Equipment", modify

    Any guidance would be greatly appreciated.

    Thanks.


  • #2
    Something like this:
    Code:
    //  RESTRICT TO POTENTIALLY USABLE OBSERVATIONS
    keep if balancedind == 1 & !missing(RDTAwt)
    drop balancedind
    
    
    //  PREPARE A CONTROLS FILE
    preserve
    keep if RDTAwt == 0
    tempfile controls
    save `controls'
    
    //  PREPARE THE CASES
    restore
    keep if RDTAwt > 0
    gen lb = 0.8*TA
    gen ub = 1.2*TA
    
    //  COMBINE THEM
    rangejoin TA lb ub using `controls', by(year ffi) prefix(ctrl_)
    ds year ffi lb ub ctrl_*, not
    rename (`r(varlist)') case_=
    
    set seed 1234 // OR WHATEVER INTEGER YOU LIKE
    gen double shuffle = runiform()
    
    //  MATCHING WITH REPLACEMENT
    by case_DSCD year (shuffle), sort: keep if _n == 1
    
    //  MATCHING WITHOUT REPLACEMENT
    sort case_DSCD year shuffle
    local i = 1
    while `i' < _N {
        drop if (case_DSCD == case_DSCD[`i'] | ctrl_DSCD == ctrl_DSCD[`i']) ///
            & year == year[`i'] in `=`i'+1'/L
        local ++i
    }
    To use this code you must install -rangejoin-, by Robert Picard, available for SSC. To run -rangejoin- you must also have -rangestat-, by Robert Picard, Nick Cox, and Roberto Ferrer, also available from SSC.

    The code is offered as is for use at your own risk. It could not be adequately tested in the example data because there are too few distinct DSCD's shown in each RDTAwt category. Also, there were no potential matches because each DSCD had a different ffi value. Nevertheless, it is based on the paradigms I usually use, and I can verify that it does not contain syntax errors. If you need further assistance with using this code, please be sure to show new example data that includes several potential matches. It might make sense to include more DSCDs and fewer years to accomplish that.

    Note that if you want to run the match with replacement, you should comment out the MATCHING WITHOUT REPLACEMENT section of the code, and vice-versa. Running both pieces of the code will produce unhelpful results.

    Added: The end results of either type of matching is a data set in which each observation is a pair of observations from the original data set, thus, in wide layout. If you want the data in long layout for subsequent use, you have to generate a new pair_id variable and then use -reshape long-
    Last edited by Clyde Schechter; 20 Jun 2022, 13:09.

    Comment


    • #3
      Hi Clyde,

      Thanks very much for your help. I will try the code and post any questions I can't figure out.

      Many thanks and best wishes,

      Ammar.

      Comment


      • #4
        Hi Clyde Schechter, (I'm on Stata 17.0) Just a quick follow up: When Matching without replacement, I get the following output:

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input long case_DSCD int year byte case_FFIC long case_capex
         1 2015  6   3730
         1 2015  6   3730
         1 2015  6   3730
         1 2015  6   3730
         1 2015  6   3730
         1 2016  6   2930
         1 2016  6   2930
         1 2016  6   2930
         1 2016  6   2930
         1 2017  6   6454
         1 2017  6   6454
         1 2017  6   6454
         1 2017  6   6454
         1 2018  6   1956
         1 2018  6   1956
         1 2019  6   1518
         7 1999  5  77569
         7 2001  5  49903
         7 2001  5  49903
         7 2001  5  49903
         7 2002  5  38382
         7 2003  5  41058
         7 2003  5  41058
         7 2004  5  57652
         7 2005  5  70080
         7 2006  5  99847
         7 2006  5  99847
         7 2007  5  98740
         7 2008  5  99736
         7 2009  5 100786
         7 2009  5 100786
         7 2010  5  75478
         7 2011  5 190574
         7 2012  5 280873
         7 2013  5 155346
         7 2013  5 155346
         7 2014  5 110576
         7 2014  5 110576
         7 2014  5 110576
         7 2014  5 110576
         7 2015  5 227649
         7 2016  5 196654
         7 2017  5 317703
         7 2018  5 699991
         7 2019  5 851796
         7 2020  5 850477
         7 2020  5 850477
        11 2012 12  10334
        11 2012 12  10334
        11 2012 12  10334
        11 2012 12  10334
        11 2012 12  10334
        11 2013 12   9639
        11 2013 12   9639
        11 2013 12   9639
        11 2013 12   9639
        11 2013 12   9639
        11 2013 12   9639
        11 2013 12   9639
        11 2014 12  13020
        11 2014 12  13020
        11 2014 12  13020
        11 2014 12  13020
        11 2015 12  15121
        11 2015 12  15121
        11 2015 12  15121
        11 2015 12  15121
        14 1999 10    897
        14 2001 10   2604
        14 2001 10   2604
        14 2001 10   2604
        14 2003 10     52
        14 2003 10     52
        14 2004 10    276
        14 2005 10    497
        14 2005 10    497
        14 2005 10    497
        14 2005 10    497
        14 2006 10   1398
        14 2007 10   3344
        14 2008 10   1212
        14 2008 10   1212
        14 2008 10   1212
        14 2009 10    604
        14 2009 10    604
        14 2009 10    604
        14 2010 10    325
        14 2010 10    325
        14 2010 10    325
        14 2010 10    325
        14 2010 10    325
        14 2010 10    325
        14 2011 10     55
        14 2011 10     55
        14 2011 10     55
        14 2012 10    113
        14 2013 10     30
        14 2014 10    106
        14 2014 10    106
        14 2014 10    106
        end
        label values case_DSCD DSCD1
        label def DSCD1 1 "130042", modify
        label def DSCD1 7 "130298", modify
        label def DSCD1 11 "130375", modify
        label def DSCD1 14 "130411", modify
        It seems that each case is being matched with all the potential control groups, leading to repeated values. However, this is not the case for the "with replacement" group. The only part of the code I have changed is using "DSCDS" instead of "DSCD" as my company identifier, but I tried to run the code using "DSCD" in case the two variables are different in properties not immediately clear to me, but the same result persists.


        Code:
        keep if balancedind == 1 & !missing(RDTAwt)
        (175,420 observations deleted)
        
        . 
        . drop balancedind
        
        . 
        . preserve
        
        . 
        . keep if RDTAwt == 0
        (17,449 observations deleted)
        
        . 
        . tempfile controls
        
        . 
        . save `controls'
        file C:\Users\44784\AppData\Local\Temp\ST_7290_000002.tmp saved as .dta format
        
        . restore
        
        . 
        . keep if RDTAwt > 0
        (19,813 observations deleted)
        
        . 
        . gen lb = 0.8*TA
        
        . 
        . gen ub = 1.2*TA
        
        . rangejoin TA lb ub using `controls', by(year ffi) prefix(ctrl_)
          (using rangestat version 1.1.1)
        
        . 
        . ds year ffi lb ub ctrl_*, not
        DSCD          marketcap     industr~klev  scaledcapexw  marketlev     NI            laggedRDTA    logsaleslag   newfirmid     indmlevwt     mlevchange    DSCDS
        FFIC          sic           logsales      TAcons2000~s  marketlevw    cso           RD_Res        profitabil~g  newfirm_size  negeqmbwt     indblevcha~e
        RD            YRINC         yearreturn    res1          industr~mlev  bookvalue     rrvlevw       tangibilit~g  RDTAwt        Qrd           rdchange
        capex         constfactor   tangibility   RDTAchange    marketlevc~e  lnbookval     rrvlevchange  industry48~g  scaledcape~t  Qcapex        returnchange
        bvps          TD            yearreturnw   bookleve~nge  scaledcape~e  absNI         DEPAM         mbratiolag    tangibilit~t  capchange     newfirmidc~e
        scaledrd      bookleverage  tangibilityw  logsalesch~e  CAP1MN        COMSHEQ       ndtaxshields  mlevcopy      profitabil~t  blevchange    changebala~d
        resdev        booklevera~w  profitabil~y  profitabil~e  scaledcape~r  lnmarketcap   ndtaxshiel~w  RDTAcopy      mbratiowt     saleschange   RDTAwtt
        ebitda        mbratio       profitabil~w  tangibilit~e  scaledcap~rw  lnabsNI       eps1sd        group_size    yearreturnwt  profitchange  marketleve~e
        PPE           mbratiow      RDTA          mbratiocha~e  CAP1SD        nii           eps1sdw       cfps          booklevera~t  tangchange    marketleve~t
        TA            negeq         RDTAw         industrybl~e  CAP1SDw       rrvlev        blevcopy      twonegcash~w  marketlevwt   mbchange      rdbalanced~d
        SALES         negeqmbratio  scaledcapex   yearreturn~e  lnTA          industry48~e  RDTAlag       condition     indblevwt     indmlevcha~e  count
        
        . 
        . rename (`r(varlist)') case_=
        
        . 
        . 
        . 
        . set seed 1234
        
        . gen double shuffle = runiform()
        
        . sort case_DSCD year shuffle
        
        . 
        . local i = 1
        
        . 
        . while `i' < _N {
          2. 
        .     drop if (case_DSCDS == case_DSCDS[`i'] | ctrl_DSCDS == ctrl_DSCDS[`i']) ///
          3. 
        .         & year == year[`i'] in `=`i'+1'/L
          4. 
        .     local ++i
          5. 
        . }
        Lastly, I'd like to ask if there is a code that is easily adjustable (for novices like myself) so that I can generate pair IDs and reshape the data long for further analysis.

        Many thanks for your help.

        Best wishes,
        Ammar.

        Comment


        • #5
          I'd like to help, but as I indicated in #2, the example data that you provided in #1 does not even contain any potential matches, so it is impossible for me to troubleshoot the code that is producing too many matches. Moreover, I cannot understand at all how what you show in #4 can be the output of the code shown there because the data doesn't even contain any ctrl_* variables.

          Please post back with new example starting data (not the results after running the code) that produces the problem you are encountering and I will see what I can do.

          I'd like to ask if there is a code that is easily adjustable (for novices like myself) so that I can generate pair IDs and reshape the data long for further analysis.
          Code:
          gen long pair_id = _n
          drop shuffle lb ub
          reshape long @RDTAwt @TA @DSCD, i(pair_id) j(case_control) string
          The same code will work after matching without replacement once we get that fixed.

          Added: I tried modifying your example data from #1 so as to make matches available and re-ran my code for matching without replacement. It does not reproduce your problem. The results have a single control matched to each case in each year in every instance. So I really won't be able to help you unless you post back example data that reproduces the problem you have.
          Last edited by Clyde Schechter; 21 Jun 2022, 16:08.

          Comment


          • #6

            Hi Clyde Schechter ,

            Thanks for your response. I've extended the dataex count to the first 750 observations (Sorry if this is too much, but there are 48 ffi categories so just trying to be on the safe side and it wouldn't let me post more characters anyways). Just in case, I also included FFIC which is a more general industry classification (Only 10 categories vs the 48 in ffi) that could be used to generate matches.

            Many thanks for your help.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input long DSCDS int year float RDTAwt double TA float ffi byte FFIC
             1 1999           0   178392 36  6
             1 2000           0   279960 36  6
             1 2001           0   376506 36  6
             1 2002           0   460890 36  6
             1 2003           0   515080 36  6
             1 2004           0   592146 36  6
             1 2005           0   704957 36  6
             1 2006           0   900030 36  6
             1 2007           0  1028851 36  6
             1 2008           0  1798857 36  6
             1 2009           0  1754039 36  6
             1 2010           0  1716317 36  6
             1 2011  .004691441  1708051 36  6
             1 2012  .013918202  1727560 36  6
             1 2013   .02107018  1677374 36  6
             1 2014  .027589554  2103174 36  6
             2 2015  .029417917  1979222 36  6
             2 2016  .034052774  2004894 36  6
             2 2017   .03758303  2073407 36  6
             2 2018   .03764191  2005064 36  6
             2 2019   .03967754  2116877 36  6
             1 2020           0        . 36  6
             1 2021           0        .  .  .
             3 1999           0  1742574 17  3
             3 2000           0  1841439 17  3
             4 2001           0  2224580 17  3
             4 2002           0  2258530 17  3
             4 2003           0  2330093 17  3
             4 2004           0  2355852 17  3
             4 2005           0  2433316 17  3
             4 2006           0  2506421 17  3
             4 2007           0  2683805 17  3
             4 2008           0  3032502 17  3
             4 2009           0  3239283 17  3
             4 2010           0  3074743 17  3
             4 2011           0  3147822 17  3
             4 2012           0  3160926 17  3
             4 2013           0  3259826 17  3
             4 2014           0  7464392 17  3
             4 2015           0  6961732 17  3
             4 2016           0  7300905 17  3
             4 2017           0  8992511 17  3
             4 2018           0  9551419 17  3
             4 2019           0 10131600 17  3
             4 2020           0 10580800 17  3
             3 2021           0        .  .  .
             5 1999           0    80216 21  3
             5 2000           0    54030 21  3
             6 2001           0    38279 21  3
             6 2002           0    36002 21  3
             6 2003           0    30346 21  3
             6 2004           0    26626 21  3
             6 2005           0    26354 21  3
             6 2006           0    27188 21  3
             6 2007           0    29300 21  3
             6 2008           0    21030 21  3
             5 2009           0        . 21  3
             5 2010           0        . 21  3
             5 2011           0        . 21  3
             5 2012           0        . 21  3
             5 2013           0        . 21  3
             5 2014           0        . 21  3
             5 2015           0        . 21  3
             5 2016           0        . 21  3
             5 2017           0        . 21  3
             5 2018           0        . 21  3
             5 2019           0        . 21  3
             5 2020           0        . 21  3
             5 2021           0        .  .  .
             7 1999           0  2280227 24  3
             7 2000           0  2162274 24  3
             7 2001           0  2025012 24  3
             7 2002           0  1887196 24  3
             7 2003           0  1838680 24  3
             7 2004           0  1933886 24  3
             7 2005           0  1839100 24  3
             7 2006           0  1962882 24  3
             7 2007           0  2079041 24  3
             7 2008           0  2090531 24  3
             7 2009           0  2252931 24  3
             7 2010           0  2363653 24  3
             7 2011           0  2569348 24  3
             7 2012           0  3122951 24  3
             7 2013           0  3685501 24  3
             7 2014           0  2453115 24  3
             8 2015           0  2319263 24  3
             8 2016           0  2685760 24  3
             8 2017           0  2858481 24  3
             8 2018           0  2780666 24  3
             8 2019           0  2860996 24  3
             8 2020           0  3728733 24  3
             7 2021           0        .  .  .
             9 1999           0        .  .  .
             9 2000           0        .  .  .
             9 2001           0        .  .  .
             9 2002           0        .  .  .
             9 2003           0        .  .  .
             9 2004           0        .  .  .
             9 2005           0        .  .  .
             9 2006           0        .  .  .
             9 2007           0        .  .  .
             9 2008           0        .  .  .
             9 2009           0        .  .  .
             9 2010           0        .  .  .
             9 2011           0        .  .  .
             9 2012           0        .  .  .
             9 2013           0        .  .  .
             9 2014           0        .  .  .
             9 2015           0        .  .  .
             9 2016           0        .  .  .
             9 2017           0        .  .  .
             9 2018           0        .  .  .
             9 2019           0        .  .  .
             9 2020           0        .  .  .
             9 2021           0        .  .  .
            10 1999           0        . 36  6
            10 2000           0        . 36  6
            10 2001           0        . 36  6
            10 2002           0        . 36  6
            10 2003           0    26883 36  6
            10 2004           0    23868 36  6
            10 2005           0    41661 36  6
            10 2006           0    75358 36  6
            10 2007           0   175769 36  6
            10 2008           0   198124 36  6
            10 2009           0   210131 36  6
            10 2010           0   222990 36  6
            10 2011           0   277173 36  6
            10 2012           0   331849 36  6
            10 2013           0   363724 36  6
            10 2014           0   475539 36  6
            10 2015           0   542551 36  6
            10 2016           0   556281 36  6
            10 2017           0   562762 36  6
            10 2018           0   678107 36  6
            10 2019           0   667535 36  6
            10 2020           0   623826 36  6
            10 2021           0        .  .  .
            11 1999  .036562283   954094 14  5
            11 2000  .027461655   981803 14  5
            12 2001  .022325253  1138272 14  5
            12 2002   .01448248  1192956 14  5
            12 2003  .015433093  1387291 14  5
            12 2004  .022542495  2442745 14  5
            12 2005  .017060725  2359883 14  5
            12 2006  .019619193  2516894 14  5
            12 2007   .02490808  2803512 14  5
            12 2008   .02400275  2821881 14  5
            12 2009   .02158773  2697890 14  5
            12 2010   .02164432  3003452 14  5
            12 2011    .0256648  3152867 14  5
            12 2012   .02503087  3372779 14  5
            12 2013   .02438523  3519130 14  5
            12 2014   .02509427  5160663 14  5
            12 2015   .01993368  9538989 14  5
            12 2016  .008436428  8100075 14  5
            12 2017  .010411015  7725664 14  5
            12 2018  .009067699  7564645 14  5
            12 2019  .007705186  9845588 14  5
            12 2020  .006014267 10430629 14  5
            11 2021           0        .  .  .
            13 1999           0    13115 13 10
            13 2000           0    31946 13 10
            13 2001           0    27253 13 10
            13 2002           0    21240 13 10
            13 2003           0    34226 13 10
            13 2004           0    99515 13 10
            13 2005           0    86125 13 10
            13 2006           0    76372 13 10
            13 2007           0    81815 13 10
            13 2008           0    91080 13 10
            13 2009           0    85031 13 10
            13 2010           0    83939 13 10
            13 2011           0    82057 13 10
            13 2012           0    78788 13 10
            13 2013    .2259735    81563 13 10
            13 2014    .2832044   125647 13 10
            13 2015   .24316537   118401 13 10
            13 2016    .2996174   110318 13 10
            13 2017    .3675737   117306 13 10
            13 2018           0   118872 13 10
            13 2019           0        . 13 10
            13 2020           0        . 13 10
            13 2021           0        .  .  .
            14 1999           0   588854 18 12
            14 2000           0   689373 18 12
            15 2001           0   975649 18 12
            15 2002           0  1865748 18 12
            15 2003           0  2185874 18 12
            15 2004           0  3102410 18 12
            15 2005           0  3669187 18 12
            15 2006           0  4499589 18 12
            15 2007           0  3697072 18 12
            15 2008           0  2621583 18 12
            15 2009           0  2021890 18 12
            15 2010           0  1895123 18 12
            15 2011           0  1974717 18 12
            15 2012           0  1975370 18 12
            15 2013           0  1981536 18 12
            15 2014           0  2063397 18 12
            15 2015           0  2095830 18 12
            15 2016           0  1903203 18 12
            15 2017           0  1913099 18 12
            15 2018           0  1914147 18 12
            15 2019           0  1710687 18 12
            15 2020           0  1782337 18 12
            14 2021           0        .  .  .
            16 1999           0    64966 32  7
            16 2000           0   269270 32  7
            16 2001           0   234976 32  7
            16 2002           0   253468 32  7
            17 2003           0   327508 32  7
            17 2004           0   397485 32  7
            17 2005           0   331052 32  7
            17 2006           0   224740 32  7
            17 2007           0   231853 32  7
            17 2008           0   203606 32  7
            17 2009           0   159592 32  7
            17 2010           0   228905 32  7
            17 2011           0   213980 32  7
            17 2012           0   151109 32  7
            17 2013           0   292222 32  7
            16 2014           0   289617 32  7
            16 2015           0        . 32  7
            16 2016           0        . 32  7
            16 2017           0        . 32  7
            16 2018           0        . 32  7
            16 2019           0        . 32  7
            16 2020           0        . 32  7
            16 2021           0        .  .  .
            18 1999           0   172923 40 12
            18 2000           0   267156 40 12
            18 2001           0   571497 40 12
            18 2002           0   670015 40 12
            18 2003           0   817419 40 12
            18 2004           0   928515 40 12
            18 2005           0  1026340 40 12
            18 2006           0   937707 40 12
            18 2007   .00577899   971359 40 12
            18 2008 .0085014915   785096 40 12
            18 2009  .011126027   751505 40 12
            18 2010  .018013187   713820 40 12
            18 2011  .034840718   731874 40 12
            19 2012   .05464739   882860 40 12
            19 2013   .06841402   793171 40 12
            19 2014   .09157673   765436 40 12
            19 2015   .09773906   812320 40 12
            18 2016           0   782865 40 12
            18 2017           0        . 40 12
            18 2018           0        . 40 12
            18 2019           0        . 40 12
            18 2020           0        . 40 12
            18 2021           0        .  .  .
            20 1999           0        .  .  .
            20 2000           0        .  .  .
            20 2001           0        .  .  .
            20 2002           0        .  .  .
            20 2003           0        .  .  .
            20 2004           0        .  .  .
            20 2005           0        .  .  .
            20 2006           0        .  .  .
            20 2007           0        .  .  .
            20 2008           0        .  .  .
            20 2009           0        .  .  .
            20 2010           0        .  .  .
            20 2011           0        .  .  .
            20 2012           0        .  .  .
            20 2013           0        .  .  .
            20 2014           0        .  .  .
            20 2015           0        .  .  .
            20 2016           0        .  .  .
            20 2017           0        .  .  .
            20 2018           0        .  .  .
            20 2019           0        .  .  .
            20 2020           0        .  .  .
            20 2021           0        .  .  .
            21 1999           0  1161470 39  3
            21 2000           0  1158963 39  3
            22 2001           0  1164413 39  3
            22 2002           0  1173733 39  3
            22 2003           0  1287788 39  3
            22 2004           0  1283813 39  3
            22 2005           0  1798434 39  3
            22 2006           0  1784000 39  3
            22 2007           0  1800700 39  3
            22 2008           0  3013100 39  3
            22 2009           0  2884400 39  3
            22 2010           0  2914900 39  3
            22 2011           0 10566000 39  3
            22 2012           0 10650000 39  3
            22 2013           0 10733400 39  3
            22 2014           0 11039700 39  3
            21 2015           0        . 39  3
            21 2016           0        . 39  3
            21 2017           0        . 39  3
            21 2018           0        . 39  3
            21 2019           0        . 39  3
            21 2020           0        . 39  3
            21 2021           0        .  .  .
            23 1999   .26402062    73387 13 10
            23 2000   .13067709    70826 13 10
            23 2001   .18483326    59096 13 10
            23 2002    .2618282    41300 13 10
            24 2003   .27898306    30096 13 10
            24 2004    .6269271    32469 13 10
            24 2005    .7281407    99248 13 10
            24 2006    .4743975    68485 13 10
            24 2007   1.3733226   142717 13 10
            24 2008   .51379305    84692 13 10
            24 2009    .8536934   142190 13 10
            24 2010    .5800197   109447 13 10
            24 2011    .5198681    82208 13 10
            24 2012    .6260218    57439 13 10
            24 2013    .7439196    48866 13 10
            24 2014   1.0599599   136874 13 10
            24 2015    .5315692   124555 13 10
            24 2016    .4898077    89847 13 10
            24 2017    .7452892   178259 13 10
            24 2018     .476206   146841 13 10
            24 2019    .7291424   175282 13 10
            24 2020     .701521   334715 13 10
            23 2021           0        .  .  .
            25 1999           0        .  .  .
            25 2000           0        .  .  .
            25 2001           0        .  .  .
            25 2002           0        .  .  .
            25 2003           0        .  .  .
            25 2004           0        .  .  .
            25 2005           0        .  .  .
            25 2006           0        .  .  .
            25 2007           0        .  .  .
            25 2008           0        .  .  .
            25 2009           0        .  .  .
            25 2010           0        .  .  .
            25 2011           0        .  .  .
            25 2012           0        .  .  .
            25 2013           0        .  .  .
            25 2014           0        .  .  .
            25 2015           0        .  .  .
            25 2016           0        .  .  .
            25 2017           0        .  .  .
            25 2018           0        .  .  .
            25 2019           0        .  .  .
            25 2020           0        .  .  .
            25 2021           0        .  .  .
            26 1999           0        .  .  .
            26 2000           0        .  .  .
            26 2001           0        .  .  .
            26 2002           0        .  .  .
            26 2003           0        .  .  .
            26 2004           0        .  .  .
            26 2005           0        .  .  .
            26 2006           0        .  .  .
            26 2007           0        .  .  .
            26 2008           0        .  .  .
            26 2009           0        .  .  .
            26 2010           0        .  .  .
            26 2011           0        .  .  .
            26 2012           0        .  .  .
            26 2013           0        .  .  .
            26 2014           0        .  .  .
            26 2015           0        .  .  .
            26 2016           0        .  .  .
            26 2017           0        .  .  .
            26 2018           0        .  .  .
            26 2019           0        .  .  .
            26 2020           0        .  .  .
            26 2021           0        .  .  .
            27 1999           0        .  .  .
            27 2000           0        .  .  .
            27 2001           0        .  .  .
            27 2002           0        .  .  .
            27 2003           0        .  .  .
            27 2004           0        .  .  .
            27 2005           0        .  .  .
            27 2006           0        .  .  .
            27 2007           0        .  .  .
            27 2008           0        .  .  .
            27 2009           0        .  .  .
            27 2010           0        .  .  .
            27 2011           0        .  .  .
            27 2012           0        .  .  .
            27 2013           0        .  .  .
            27 2014           0        .  .  .
            27 2015           0        .  .  .
            27 2016           0        .  .  .
            27 2017           0        .  .  .
            27 2018           0        .  .  .
            27 2019           0        .  .  .
            27 2020           0        .  .  .
            27 2021           0        .  .  .
            28 1999           0        .  .  .
            28 2000           0        .  .  .
            28 2001           0        .  .  .
            28 2002           0        .  .  .
            28 2003           0        .  .  .
            28 2004           0        .  .  .
            28 2005           0        .  .  .
            28 2006           0        .  .  .
            28 2007           0        .  .  .
            28 2008           0        .  .  .
            28 2009           0        .  .  .
            28 2010           0        .  .  .
            28 2011           0        .  .  .
            28 2012           0        .  .  .
            28 2013           0        .  .  .
            28 2014           0        .  .  .
            28 2015           0        .  .  .
            28 2016           0        .  .  .
            28 2017           0        .  .  .
            28 2018           0        .  .  .
            28 2019           0        .  .  .
            28 2020           0        .  .  .
            28 2021           0        .  .  .
            29 1999           0   125727 41  9
            29 2000           0   205880 41  9
            30 2001           0   287171 41  9
            30 2002           0   359032 41  9
            30 2003           0   344347 41  9
            30 2004           0   413192 41  9
            30 2005           0   467070 41  9
            30 2006           0   613219 41  9
            30 2007           0   738448 41  9
            30 2008           0   772206 41  9
            30 2009           0   748631 41  9
            30 2010           0   859750 41  9
            30 2011           0  1182188 41  9
            30 2012           0  1201806 41  9
            30 2013           0  1164183 41  9
            30 2014           0  1335124 41  9
            30 2015           0  1476941 41  9
            30 2016           0  1462372 41  9
            30 2017           0  1688812 41  9
            30 2018           0  1923096 41  9
            30 2019           0  2042537 41  9
            30 2020           0  1667464 41  9
            29 2021           0        .  .  .
            31 1999           0        .  .  .
            31 2000           0        .  .  .
            31 2001           0        .  .  .
            31 2002           0        .  .  .
            31 2003           0        .  .  .
            31 2004           0        .  .  .
            31 2005           0        .  .  .
            31 2006           0        .  .  .
            31 2007           0        .  .  .
            31 2008           0        .  .  .
            31 2009           0        .  .  .
            31 2010           0        .  .  .
            31 2011           0        .  .  .
            31 2012           0        .  .  .
            31 2013           0        .  .  .
            31 2014           0        .  .  .
            31 2015           0        .  .  .
            31 2016           0        .  .  .
            31 2017           0        .  .  .
            31 2018           0        .  .  .
            31 2019           0        .  .  .
            31 2020           0        .  .  .
            31 2021           0        .  .  .
            32 1999           0        .  .  .
            32 2000           0        .  .  .
            32 2001           0        .  .  .
            32 2002           0        .  .  .
            32 2003           0        .  .  .
            32 2004           0        .  .  .
            32 2005           0        .  .  .
            32 2006           0        .  .  .
            32 2007           0        .  .  .
            32 2008           0        .  .  .
            32 2009           0        .  .  .
            32 2010           0        .  .  .
            32 2011           0        .  .  .
            32 2012           0        .  .  .
            32 2013           0        .  .  .
            32 2014           0        .  .  .
            32 2015           0        .  .  .
            32 2016           0        .  .  .
            32 2017           0        .  .  .
            32 2018           0        .  .  .
            32 2019           0        .  .  .
            32 2020           0        .  .  .
            32 2021           0        .  .  .
            33 1999           0        .  .  .
            33 2000           0        .  .  .
            33 2001           0        .  .  .
            33 2002           0        .  .  .
            33 2003           0        .  .  .
            33 2004           0        .  .  .
            33 2005           0        .  .  .
            33 2006           0        .  .  .
            33 2007           0        .  .  .
            33 2008           0        .  .  .
            33 2009           0        .  .  .
            33 2010           0        .  .  .
            33 2011           0        .  .  .
            33 2012           0        .  .  .
            33 2013           0        .  .  .
            33 2014           0        .  .  .
            33 2015           0        .  .  .
            33 2016           0        .  .  .
            33 2017           0        .  .  .
            33 2018           0        .  .  .
            33 2019           0        .  .  .
            33 2020           0        .  .  .
            33 2021           0        .  .  .
            34 1999           0        .  .  .
            34 2000           0        .  .  .
            34 2001           0        .  .  .
            34 2002           0        .  .  .
            34 2003           0        .  .  .
            34 2004           0        .  .  .
            34 2005           0        .  .  .
            34 2006           0        .  .  .
            34 2007           0        .  .  .
            34 2008           0        .  .  .
            34 2009           0        .  .  .
            34 2010           0        .  .  .
            34 2011           0        .  .  .
            34 2012           0        .  .  .
            34 2013           0        .  .  .
            34 2014           0        .  .  .
            34 2015           0        .  .  .
            34 2016           0        .  .  .
            34 2017           0        .  .  .
            34 2018           0        .  .  .
            34 2019           0        .  .  .
            34 2020           0        .  .  .
            34 2021           0        .  .  .
            35 1999           0        .  .  .
            35 2000           0        .  .  .
            35 2001           0        .  .  .
            35 2002           0        .  .  .
            35 2003           0        .  .  .
            35 2004           0        .  .  .
            35 2005           0        .  .  .
            35 2006           0        .  .  .
            35 2007           0        .  .  .
            35 2008           0        .  .  .
            35 2009           0        .  .  .
            35 2010           0        .  .  .
            35 2011           0        .  .  .
            35 2012           0        .  .  .
            35 2013           0        .  .  .
            35 2014           0        .  .  .
            35 2015           0        .  .  .
            35 2016           0        .  .  .
            35 2017           0        .  .  .
            35 2018           0        .  .  .
            35 2019           0        .  .  .
            35 2020           0        .  .  .
            35 2021           0        .  .  .
            36 1999           0        .  .  .
            36 2000           0        .  .  .
            36 2001           0        .  .  .
            36 2002           0        .  .  .
            36 2003           0        .  .  .
            36 2004           0        .  .  .
            36 2005           0        .  .  .
            36 2006           0        .  .  .
            36 2007           0        .  .  .
            36 2008           0        .  .  .
            36 2009           0        .  .  .
            36 2010           0        .  .  .
            36 2011           0        .  .  .
            36 2012           0        .  .  .
            36 2013           0        .  .  .
            36 2014           0        .  .  .
            36 2015           0        .  .  .
            36 2016           0        .  .  .
            36 2017           0        .  .  .
            36 2018           0        .  .  .
            36 2019           0        .  .  .
            36 2020           0        .  .  .
            36 2021           0        .  .  .
            37 1999           0        .  .  .
            37 2000           0        .  .  .
            37 2001           0        .  .  .
            37 2002           0        .  .  .
            37 2003           0        .  .  .
            37 2004           0        .  .  .
            37 2005           0        .  .  .
            37 2006           0        .  .  .
            37 2007           0        .  .  .
            37 2008           0        .  .  .
            37 2009           0        .  .  .
            37 2010           0        .  .  .
            37 2011           0        .  .  .
            37 2012           0        .  .  .
            37 2013           0        .  .  .
            37 2014           0        .  .  .
            37 2015           0        .  .  .
            37 2016           0        .  .  .
            37 2017           0        .  .  .
            37 2018           0        .  .  .
            37 2019           0        .  .  .
            37 2020           0        .  .  .
            37 2021           0        .  .  .
            38 1999           0        .  .  .
            38 2000           0        .  .  .
            38 2001           0        .  .  .
            38 2002           0        .  .  .
            38 2003           0        .  .  .
            38 2004           0        .  .  .
            38 2005           0        .  .  .
            38 2006           0        .  .  .
            38 2007           0        .  .  .
            38 2008           0        .  .  .
            38 2009           0        .  .  .
            38 2010           0        .  .  .
            38 2011           0        .  .  .
            38 2012           0        .  .  .
            38 2013           0        .  .  .
            38 2014           0        .  .  .
            38 2015           0        .  .  .
            38 2016           0        .  .  .
            38 2017           0        .  .  .
            38 2018           0        .  .  .
            38 2019           0        .  .  .
            38 2020           0        .  .  .
            38 2021           0        .  .  .
            39 1999           0        .  .  .
            39 2000           0        .  .  .
            39 2001           0        .  .  .
            39 2002           0        .  .  .
            39 2003           0        .  .  .
            39 2004           0        .  .  .
            39 2005           0        .  .  .
            39 2006           0        .  .  .
            39 2007           0        .  .  .
            39 2008           0        .  .  .
            39 2009           0        .  .  .
            39 2010           0        .  .  .
            39 2011           0        .  .  .
            39 2012           0        .  .  .
            39 2013           0        .  .  .
            39 2014           0        .  .  .
            39 2015           0        .  .  .
            39 2016           0        .  .  .
            39 2017           0        .  .  .
            39 2018           0        .  .  .
            39 2019           0        .  .  .
            39 2020           0        .  .  .
            39 2021           0        .  .  .
            40 1999           0        . 34  6
            40 2000           0    68551 34  6
            40 2001           0    56858 34  6
            40 2002           0    65046 34  6
            40 2003           0    53550 34  6
            40 2004           0    61388 34  6
            40 2005           0    83348 34  6
            40 2006           0   101346 34  6
            40 2007           0   130851 34  6
            40 2008           0   140733 34  6
            40 2009           0   158599 34  6
            40 2010           0   162529 34  6
            40 2011           0   190519 34  6
            40 2012           0   500041 34  6
            40 2013           0   364528 34  6
            40 2014           0   316239 34  6
            40 2015           0   421499 34  6
            40 2016           0   413136 34  6
            40 2017           0   422593 34  6
            40 2018           0   483941 34  6
            40 2019           0   622616 34  6
            40 2020           0   758079 34  6
            40 2021           0        .  .  .
            41 1999   .06577428     7496 12 10
            41 2000    .3357791    19306 12 10
            42 2001    .2462965    29984 12 10
            42 2002    .1324373    23928 12 10
            42 2003    .1076981    17002 12 10
            42 2004   .14074814    19391 12 10
            42 2005   .12165438    17495 12 10
            42 2006   .13089454    32079 12 10
            42 2007   .07300726    34759 12 10
            42 2008    .0950833    30228 12 10
            42 2009   .11297473    30447 12 10
            41 2010           0        . 12 10
            41 2011           0        . 12 10
            41 2012           0        . 12 10
            41 2013           0        . 12 10
            41 2014           0        . 12 10
            41 2015           0        . 12 10
            41 2016           0        . 12 10
            41 2017           0        . 12 10
            41 2018           0        . 12 10
            41 2019           0        . 12 10
            41 2020           0        . 12 10
            41 2021           0        .  .  .
            43 1999           0    46628 42  9
            43 2000           0    45942 42  9
            43 2001           0    42974 42  9
            43 2002           0    37111 42  9
            44 2003           0    33970 42  9
            44 2004           0    32612 42  9
            44 2005           0    36348 42  9
            44 2006           0    64323 42  9
            44 2007           0    72093 42  9
            44 2008           0    62506 42  9
            44 2009           0    52747 42  9
            44 2010           0    57146 42  9
            44 2011           0    61428 42  9
            44 2012           0    67359 42  9
            44 2013           0    97332 42  9
            44 2014           0   125327 42  9
            44 2015           0   111627 42  9
            44 2016           0    91478 42  9
            43 2017           0        . 42  9
            43 2018           0        . 42  9
            43 2019           0        . 42  9
            43 2020           0        . 42  9
            43 2021           0        .  .  .
            45 1999   .01012536   483800  2  1
            45 2000 .0082678795   804700  2  1
            46 2001  .010935753   817900  2  1
            46 2002  .012226433   832500  2  1
            46 2003  .014894895   794300  2  1
            46 2004   .01812917  1221600  2  1
            46 2005   .01227898  1269500  2  1
            46 2006  .013233556  1507500  2  1
            46 2007   .00676617  1853100  2  1
            46 2008  .012411634  5343900  2  1
            46 2009  .007185763  5452200  2  1
            46 2010  .003869997  6804900  2  1
            46 2011  .003468089  6333200  2  1
            46 2012 .0029684836  4538800  2  1
            45 2013           0        .  2  1
            45 2014           0        .  2  1
            45 2015           0        .  2  1
            45 2016           0        .  2  1
            45 2017           0        .  2  1
            45 2018           0        .  2  1
            45 2019           0        .  2  1
            45 2020           0        .  2  1
            45 2021           0        .  .  .
            47 1999  .025549324   244026 34 12
            47 2000   .01924385   250466 34 12
            48 2001  .013055664   349700 34 12
            48 2002  .010477552   341314 34 12
            48 2003  .011953802   334046 34 12
            48 2004  .011172114   442091 34 12
            48 2005   .00575221   465110 34 12
            48 2006  .006540388   590568 34 12
            48 2007  .005205159   606455 34 12
            48 2008  .005360662   602213 34 12
            47 2009  .006085887   584167 34 12
            49 2010  .007465331   561506 34 12
            49 2011  .016518079   598240 34 12
            49 2012   .01608886   614067 34 12
            end
            label values DSCDS DSCD_Sl
            label def DSCD_Sl 1 "130042", modify
            label def DSCD_Sl 2 "130042_01", modify
            label def DSCD_Sl 3 "130062", modify
            label def DSCD_Sl 4 "130062_02", modify
            label def DSCD_Sl 5 "130079", modify
            label def DSCD_Sl 6 "130079_02", modify
            label def DSCD_Sl 7 "130086", modify
            label def DSCD_Sl 8 "130086_01", modify
            label def DSCD_Sl 9 "130088", modify
            label def DSCD_Sl 10 "130104", modify
            label def DSCD_Sl 11 "130298", modify
            label def DSCD_Sl 12 "130298_02", modify
            label def DSCD_Sl 13 "130316", modify
            label def DSCD_Sl 14 "130324", modify
            label def DSCD_Sl 15 "130324_02", modify
            label def DSCD_Sl 16 "130371", modify
            label def DSCD_Sl 17 "130371_02", modify
            label def DSCD_Sl 18 "130375", modify
            label def DSCD_Sl 19 "130375_01", modify
            label def DSCD_Sl 20 "130399", modify
            label def DSCD_Sl 21 "130409", modify
            label def DSCD_Sl 22 "130409_02", modify
            label def DSCD_Sl 23 "130411", modify
            label def DSCD_Sl 24 "130411_03", modify
            label def DSCD_Sl 25 "130412", modify
            label def DSCD_Sl 26 "130421", modify
            label def DSCD_Sl 27 "130437", modify
            label def DSCD_Sl 28 "130473", modify
            label def DSCD_Sl 29 "130485", modify
            label def DSCD_Sl 30 "130485_01", modify
            label def DSCD_Sl 31 "130502", modify
            label def DSCD_Sl 32 "130511", modify
            label def DSCD_Sl 33 "130524", modify
            label def DSCD_Sl 34 "130556", modify
            label def DSCD_Sl 35 "130562", modify
            label def DSCD_Sl 36 "130580", modify
            label def DSCD_Sl 37 "130591", modify
            label def DSCD_Sl 38 "130610", modify
            label def DSCD_Sl 39 "13065K", modify
            label def DSCD_Sl 40 "130670", modify
            label def DSCD_Sl 41 "130685", modify
            label def DSCD_Sl 42 "130685_01", modify
            label def DSCD_Sl 43 "130719", modify
            label def DSCD_Sl 44 "130719_01", modify
            label def DSCD_Sl 45 "130720", modify
            label def DSCD_Sl 46 "130720_02", modify
            label def DSCD_Sl 47 "130737", modify
            label def DSCD_Sl 48 "130737_02", modify
            label def DSCD_Sl 49 "130737_03", modify
            label values ffi ffi
            label def ffi 2 "Food Products", modify
            label def ffi 12 "Medical Equipment", modify
            label def ffi 13 "Pharmaceutical Products", modify
            label def ffi 14 "Chemicals", modify
            label def ffi 17 "Construction Materials", modify
            label def ffi 18 "Construction", modify
            label def ffi 21 "Machinery", modify
            label def ffi 24 "Aircraft", modify
            label def ffi 32 "Communication", modify
            label def ffi 34 "Business Services", modify
            label def ffi 36 "Electronic Equipment", modify
            label def ffi 39 "Shipping Containers", modify
            label def ffi 40 "Transportation", modify
            label def ffi 41 "Wholesale", modify
            label def ffi 42 "Retail", modify



            Thanks again,
            Ammar.

            Comment


            • #7
              Hi @Clyde,

              My apologies, I just saw your added comment and realised I didn't post the output I get: I've added some of the ctrl_ variables to provided a clearer picture of what I'm getting as output:

              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input long case_DSCDS int year float ffi long case_capex float case_RDTAwt long(ctrl_DSCDS ctrl_capex) float ctrl_RDTAwt
               2 2015 36   3730  .029417917  6411   142000 0
               2 2015 36   3730  .029417917  4905    10488 0
               2 2015 36   3730  .029417917  1876       21 0
               2 2015 36   3730  .029417917  5337    37128 0
               2 2015 36   3730  .029417917  8412     1766 0
               2 2016 36   2930  .034052774  1876        8 0
               2 2016 36   2930  .034052774  6411   172000 0
               2 2016 36   2930  .034052774  8412     2258 0
               2 2016 36   2930  .034052774  5337    30478 0
               2 2017 36   6454   .03758303  5337    50786 0
               2 2017 36   6454   .03758303  1876      132 0
               2 2017 36   6454   .03758303  6411   195000 0
               2 2017 36   6454   .03758303 10700   339872 0
               2 2018 36   1956   .03764191  6411   178000 0
               2 2018 36   1956   .03764191  5337    62808 0
               2 2019 36   1518   .03967754  5337    32576 0
              11 1999 14  77569  .036562283  6732    14427 0
              12 2001 14  49903  .022325253  6733    17848 0
              12 2001 14  49903  .022325253  9438    68153 0
              12 2001 14  49903  .022325253 11167    15204 0
              12 2002 14  38382   .01448248 11167    25186 0
              12 2003 14  41058  .015433093  9438   355670 0
              12 2003 14  41058  .015433093 11167     8639 0
              12 2004 14  57652  .022542495     .        . .
              12 2005 14  70080  .017060725  9438   171842 0
              12 2006 14  99847  .019619193  6733    90770 0
              12 2006 14  99847  .019619193  9438   822903 0
              12 2007 14  98740   .02490808  9438  1043800 0
              12 2008 14  99736   .02400275  3246   141800 0
              12 2009 14 100786   .02158773  7775      755 0
              12 2009 14 100786   .02158773  3246   235700 0
              12 2010 14  75478   .02164432  7775     5279 0
              12 2011 14 190574    .0256648  6917    27889 0
              12 2012 14 280873   .02503087     .        . .
              12 2013 14 155346   .02438523  9438   726604 0
              12 2013 14 155346   .02438523  1638    76400 0
              12 2014 14 110576   .02509427  7775     5345 0
              12 2014 14 110576   .02509427  6733   210500 0
              12 2014 14 110576   .02509427  8368   670529 0
              12 2014 14 110576   .02509427  6889   528000 0
              12 2015 14 227649   .01993368     .        . .
              12 2016 14 196654  .008436428     .        . .
              12 2017 14 317703  .010411015  6889   526000 0
              12 2018 14 699991  .009067699  6889   612000 0
              12 2019 14 851796  .007705186  3578    39497 0
              12 2020 14 850477  .006014267  3246   309000 0
              12 2020 14 850477  .006014267  3578    82723 0
              19 2012 40  10334   .05464739  4127   105084 0
              19 2012 40  10334   .05464739  2047   155243 0
              19 2012 40  10334   .05464739  4487     1250 0
              19 2012 40  10334   .05464739  4525    47026 0
              19 2012 40  10334   .05464739  3633    37278 0
              19 2013 40   9639   .06841402  9534  1195903 0
              19 2013 40   9639   .06841402  4127   177516 0
              19 2013 40   9639   .06841402 10002   367169 0
              19 2013 40   9639   .06841402  4525    39302 0
              19 2013 40   9639   .06841402  7073     4637 0
              19 2013 40   9639   .06841402  7212    25223 0
              19 2013 40   9639   .06841402  7052   180672 0
              19 2014 40  13020   .09157673  9534   962442 0
              19 2014 40  13020   .09157673  5603      880 0
              19 2014 40  13020   .09157673 10002   570001 0
              19 2014 40  13020   .09157673   164     6542 0
              19 2015 40  15121   .09773906  9000    88078 0
              19 2015 40  15121   .09773906 10002   497214 0
              19 2015 40  15121   .09773906  8902   232850 0
              19 2015 40  15121   .09773906  9534   697136 0
              23 1999 13    897   .26402062     .        . .
              23 2001 13   2604   .18483326   174      614 0
              23 2001 13   2604   .18483326 12003    12155 0
              23 2001 13   2604   .18483326  5966     1040 0
              24 2003 13     52   .27898306   370      393 0
              24 2003 13     52   .27898306  6441     1086 0
              24 2004 13    276    .6269271     .        . .
              24 2005 13    497    .7281407  6441     3858 0
              24 2005 13    497    .7281407   174     6538 0
              24 2005 13    497    .7281407  6715       38 0
              24 2005 13    497    .7281407  3010    10054 0
              24 2006 13   1398    .4743975     .        . .
              24 2007 13   3344   1.3733226  2790     7299 0
              24 2008 13   1212   .51379305  4588    22155 0
              24 2008 13   1212   .51379305   174     6651 0
              24 2008 13   1212   .51379305  3810     1107 0
              24 2009 13    604    .8536934  7156    77929 0
              24 2009 13    604    .8536934  9327       26 0
              24 2009 13    604    .8536934  2790      671 0
              24 2010 13    325    .5800197  2903     1190 0
              24 2010 13    325    .5800197  2790      727 0
              24 2010 13    325    .5800197  7156    60082 0
              24 2010 13    325    .5800197  2951        0 0
              24 2010 13    325    .5800197   174     1344 0
              24 2010 13    325    .5800197  4561        0 0
              24 2011 13     55    .5198681  2790      837 0
              24 2011 13     55    .5198681  4286      871 0
              24 2011 13     55    .5198681  6690   726357 0
              24 2012 13    113    .6260218  2903     3099 0
              24 2013 13     30    .7439196     .        . .
              24 2014 13    106   1.0599599  7868     2161 0
              24 2014 13    106   1.0599599  7156    92676 0
              24 2014 13    106   1.0599599 10280    10593 0
              24 2014 13    106   1.0599599  7084    38149 0
              24 2015 13   5122    .5315692 11492    99889 0
              24 2015 13   5122    .5315692   251     1708 0
              24 2016 13   5277    .4898077  3741        0 0
              24 2017 13    328    .7452892 11492   132304 0
              24 2017 13    328    .7452892   251     5354 0
              24 2017 13    328    .7452892  7868      324 0
              24 2018 13    366     .476206  2143    56435 0
              24 2018 13    366     .476206  8789 12670000 0
              24 2018 13    366     .476206   251     4081 0
              24 2019 13    343    .7291424  2952        0 0
              24 2020 13    514     .701521   276   906000 0
              24 2020 13    514     .701521  8789  5640000 0
              24 2020 13    514     .701521  7156   203139 0
              42 2001 12   1245    .2462965     .        . .
              42 2002 12    564    .1324373  2838      836 0
              42 2002 12    564    .1324373  6766    70136 0
              42 2003 12    273    .1076981  4714     1782 0
              42 2004 12    200   .14074814     .        . .
              42 2005 12    325   .12165438     .        . .
              42 2006 12    464   .13089454  2838      275 0
              42 2007 12    565   .07300726  4437      232 0
              42 2008 12    324    .0950833     .        . .
              42 2009 12    235   .11297473     .        . .
              45 1999  2  20500   .01012536     .        . .
              46 2001  2  35700  .010935753  5244      455 0
              46 2002  2  29100  .012226433  5244      546 0
              46 2003  2  36100  .014894895  8145    40312 0
              46 2003  2  36100  .014894895  5244      156 0
              46 2004  2  53800   .01812917     .        . .
              46 2005  2  56900   .01227898     .        . .
              46 2006  2  58100  .013233556     .        . .
              46 2007  2  51700   .00676617  9669   419565 0
              46 2008  2  62500  .012411634     .        . .
              46 2009  2 115000  .007185763     .        . .
              46 2010  2 128900  .003869997  9540   182700 0
              46 2011  2 141100  .003468089     .        . .
              46 2012  2 159800 .0029684836  9241    25725 0
              47 1999 34   3708  .025549324  8332    29067 0
              47 1999 34   3708  .025549324  3785        0 0
              47 1999 34   3708  .025549324  6924     3960 0
              47 1999 34   3708  .025549324  3310     7789 0
              47 1999 34   3708  .025549324  3580    14261 0
              47 1999 34   3708  .025549324  9740     5441 0
              47 1999 34   3708  .025549324  6875    16495 0
              47 1999 34   3708  .025549324  9929   120209 0
              47 1999 34   3708  .025549324 10187     5840 0
              48 2001 34   6961  .013055664  8250   143795 0
              48 2001 34   6961  .013055664  9930   155987 0
              48 2001 34   6961  .013055664  6505   287000 0
              48 2001 34   6961  .013055664  7711     6403 0
              48 2001 34   6961  .013055664  6876    30143 0
              48 2001 34   6961  .013055664  9741    17818 0
              48 2001 34   6961  .013055664  5143     2114 0
              48 2001 34   6961  .013055664  2115     1056 0
              48 2001 34   6961  .013055664   403     1992 0
              48 2001 34   6961  .013055664  8539   930000 0
              48 2001 34   6961  .013055664  6387     2087 0
              48 2001 34   6961  .013055664  7974    13516 0
              48 2001 34   6961  .013055664  3581    15741 0
              48 2002 34   2546  .010477552  9930   156181 0
              48 2002 34   2546  .010477552  2115     1323 0
              48 2002 34   2546  .010477552  9741    36600 0
              48 2002 34   2546  .010477552  6281     3112 0
              48 2002 34   2546  .010477552  2200     2867 0
              48 2002 34   2546  .010477552  7711     3544 0
              48 2002 34   2546  .010477552  3581    15540 0
              48 2002 34   2546  .010477552  8250   157846 0
              48 2003 34   1236  .011953802  7711     3065 0
              48 2003 34   1236  .011953802  8250    97225 0
              48 2003 34   1236  .011953802   410    13013 0
              48 2003 34   1236  .011953802  9207   963742 0
              48 2003 34   1236  .011953802  8792     3127 0
              48 2003 34   1236  .011953802   662    10612 0
              48 2003 34   1236  .011953802  5765     6899 0
              48 2003 34   1236  .011953802  2200     5482 0
              48 2003 34   1236  .011953802  6328     6582 0
              48 2003 34   1236  .011953802  4041    11382 0
              48 2003 34   1236  .011953802  9930   211979 0
              48 2004 34   3393  .011172114  3088     1260 0
              48 2004 34   3393  .011172114  2417    31308 0
              48 2004 34   3393  .011172114  8333    40243 0
              48 2004 34   3393  .011172114  9930   181453 0
              48 2004 34   3393  .011172114  6505   579000 0
              48 2004 34   3393  .011172114  5247    10135 0
              48 2004 34   3393  .011172114  5765    10404 0
              48 2004 34   3393  .011172114 12232     4956 0
              48 2004 34   3393  .011172114  2200     4370 0
              48 2004 34   3393  .011172114  2115     1742 0
              48 2004 34   3393  .011172114   114    12336 0
              48 2004 34   3393  .011172114  8250   179286 0
              48 2004 34   3393  .011172114  6387     5847 0
              48 2004 34   3393  .011172114  9207  1054938 0
              48 2004 34   3393  .011172114  8347    14726 0
              48 2004 34   3393  .011172114  3483       30 0
              48 2004 34   3393  .011172114  7711     7039 0
              48 2004 34   3393  .011172114   183     9323 0
              48 2004 34   3393  .011172114  1936     6751 0
              48 2004 34   3393  .011172114   662     8441 0
              48 2004 34   3393  .011172114  7974    11081 0
              end
              label values case_DSCDS DSCD_Sl
              label values ctrl_DSCDS DSCD_Sl
              label def DSCD_Sl 2 "130042_01", modify
              label def DSCD_Sl 11 "130298", modify
              label def DSCD_Sl 12 "130298_02", modify
              label def DSCD_Sl 19 "130375_01", modify
              label def DSCD_Sl 23 "130411", modify
              label def DSCD_Sl 24 "130411_03", modify
              label def DSCD_Sl 42 "130685_01", modify
              label def DSCD_Sl 45 "130720", modify
              label def DSCD_Sl 46 "130720_02", modify
              label def DSCD_Sl 47 "130737", modify
              label def DSCD_Sl 48 "130737_02", modify
              label def DSCD_Sl 114 "131946_02", modify
              label def DSCD_Sl 164 "133573_02", modify
              label def DSCD_Sl 174 "133956_02", modify
              label def DSCD_Sl 183 "134053_02", modify
              label def DSCD_Sl 251 "135466_03", modify
              label def DSCD_Sl 276 "13769H_02", modify
              label def DSCD_Sl 370 "146362", modify
              label def DSCD_Sl 403 "14769Q_01", modify
              label def DSCD_Sl 410 "14775P_01", modify
              label def DSCD_Sl 662 "154981_02", modify
              label def DSCD_Sl 1638 "263987_02", modify
              label def DSCD_Sl 1876 "26773X_01", modify
              label def DSCD_Sl 1936 "27101E_01", modify
              label def DSCD_Sl 2047 "27306C_01", modify
              label def DSCD_Sl 2115 "274715_02", modify
              label def DSCD_Sl 2143 "2754KJ", modify
              label def DSCD_Sl 2200 "277287_02", modify
              label def DSCD_Sl 2417 "281834_01", modify
              label def DSCD_Sl 2790 "29157J_01", modify
              label def DSCD_Sl 2838 "292461_01", modify
              label def DSCD_Sl 2903 "292915_01", modify
              label def DSCD_Sl 2951 "29502N_02", modify
              label def DSCD_Sl 2952 "29502N_03", modify
              label def DSCD_Sl 3010 "29769C_01", modify
              label def DSCD_Sl 3088 "299267_01", modify
              label def DSCD_Sl 3246 "31109K_01", modify
              label def DSCD_Sl 3310 "311837", modify
              label def DSCD_Sl 3483 "32096X_01", modify
              label def DSCD_Sl 3578 "32521X", modify
              label def DSCD_Sl 3580 "325240", modify
              label def DSCD_Sl 3581 "325240_02", modify
              label def DSCD_Sl 3633 "325800_02", modify
              label def DSCD_Sl 3741 "326913_01", modify
              label def DSCD_Sl 3785 "327330", modify
              label def DSCD_Sl 3810 "327646_02", modify
              label def DSCD_Sl 4041 "357142_02", modify
              label def DSCD_Sl 4127 "35964J_01", modify
              label def DSCD_Sl 4286 "412020", modify
              label def DSCD_Sl 4437 "501143_02", modify
              label def DSCD_Sl 4487 "50370J_01", modify
              label def DSCD_Sl 4525 "50547P_01", modify
              label def DSCD_Sl 4561 "50707N_01", modify
              label def DSCD_Sl 4588 "50887W_01", modify
              label def DSCD_Sl 4714 "511025_02", modify
              label def DSCD_Sl 4905 "515148_03", modify
              label def DSCD_Sl 5143 "51985U_01", modify
              label def DSCD_Sl 5244 "541948_02", modify
              label def DSCD_Sl 5247 "541989_02", modify
              label def DSCD_Sl 5337 "543614_02", modify
              label def DSCD_Sl 5603 "548369_02", modify
              label def DSCD_Sl 5765 "677549_02", modify
              label def DSCD_Sl 5966 "683257_01", modify
              label def DSCD_Sl 6281 "694834_01", modify
              label def DSCD_Sl 6328 "696306_01", modify
              label def DSCD_Sl 6387 "696894_01", modify
              label def DSCD_Sl 6411 "69819D_01", modify
              label def DSCD_Sl 6441 "699629_01", modify
              label def DSCD_Sl 6505 "702017_02", modify
              label def DSCD_Sl 6690 "74034D_01", modify
              label def DSCD_Sl 6715 "741491_03", modify
              label def DSCD_Sl 6732 "741702", modify
              label def DSCD_Sl 6733 "741702_02", modify
              label def DSCD_Sl 6766 "745121_02", modify
              label def DSCD_Sl 6875 "755666", modify
              label def DSCD_Sl 6876 "755666_02", modify
              label def DSCD_Sl 6889 "75586W_01", modify
              label def DSCD_Sl 6917 "75643Q_01", modify
              label def DSCD_Sl 6924 "756595", modify
              label def DSCD_Sl 7052 "77415F", modify
              label def DSCD_Sl 7073 "77444M_01", modify
              label def DSCD_Sl 7084 "7747M5", modify
              label def DSCD_Sl 7156 "777868_02", modify
              label def DSCD_Sl 7212 "86516H_01", modify
              label def DSCD_Sl 7711 "873859_02", modify
              label def DSCD_Sl 7775 "874309_02", modify
              label def DSCD_Sl 7868 "8750AA_01", modify
              label def DSCD_Sl 7974 "877159_02", modify
              label def DSCD_Sl 8145 "879541_02", modify
              label def DSCD_Sl 8250 "883119_02", modify
              label def DSCD_Sl 8332 "883938", modify
              label def DSCD_Sl 8333 "883938_02", modify
              label def DSCD_Sl 8347 "884018_02", modify
              label def DSCD_Sl 8368 "884358_01", modify
              label def DSCD_Sl 8412 "884848_01", modify
              label def DSCD_Sl 8539 "889310_01", modify
              label def DSCD_Sl 8789 "894570_01", modify
              label def DSCD_Sl 8792 "894637", modify
              label def DSCD_Sl 8902 "89591X_01", modify
              label def DSCD_Sl 9000 "90228J_01", modify
              label def DSCD_Sl 9207 "905288_02", modify
              label def DSCD_Sl 9241 "905458_01", modify
              label def DSCD_Sl 9327 "905882_01", modify
              label def DSCD_Sl 9438 "906544_02", modify
              label def DSCD_Sl 9534 "906940_02", modify
              label def DSCD_Sl 9540 "906974_02", modify
              label def DSCD_Sl 9669 "912050_01", modify
              label def DSCD_Sl 9740 "912447", modify
              label def DSCD_Sl 9741 "912447_02", modify
              label def DSCD_Sl 9929 "916747", modify
              label def DSCD_Sl 9930 "916747_02", modify
              label def DSCD_Sl 10002 "921002_01", modify
              label def DSCD_Sl 10187 "921776", modify
              label def DSCD_Sl 10280 "9225TD", modify
              label def DSCD_Sl 10700 "93204F_01", modify
              label def DSCD_Sl 11167 "944528_02", modify
              label def DSCD_Sl 11492 "9518NV_01", modify
              label def DSCD_Sl 12003 "982796_02", modify
              label def DSCD_Sl 12232 "992484_02", modify
              label values ffi ffi
              label def ffi 2 "Food Products", modify
              label def ffi 12 "Medical Equipment", modify
              label def ffi 13 "Pharmaceutical Products", modify
              label def ffi 14 "Chemicals", modify
              label def ffi 34 "Business Services", modify
              label def ffi 36 "Electronic Equipment", modify
              label def ffi 40 "Transportation", modify
              Thanks for all your help and my apologies for the errors in my posts.

              Best wishes,
              Ammar.

              Comment


              • #8
                Thank you. But this expanded example data does not reproduce the problem you reported. It produces only one matched result for each case_DSCDS in each year.
                Code:
                . //  PREPARE A CONTROLS FILE
                . preserve
                
                . keep if RDTAwt == 0
                (106 observations deleted)
                
                . tempfile controls
                
                . save `controls'
                file C:\Users\clyde\AppData\Local\Temp\ST_f948_000002.tmp saved as .dta format
                
                .
                . //  PREPARE THE CASES
                . restore
                
                . keep if RDTAwt > 0
                (644 observations deleted)
                
                . gen lb = 0.8*TA
                
                . gen ub = 1.2*TA
                
                .
                . //  COMBINE THEM
                . rangejoin TA lb ub using `controls', by(year ffi) prefix(ctrl_)
                  (using rangestat version 1.1.1)
                
                . ds year ffi lb ub ctrl_*, not
                DSCDS   RDTAwt  TA      FFIC
                
                . rename (`r(varlist)') case_=
                
                .
                . set seed 1234 // OR WHATEVER INTEGER YOU LIKE
                
                . gen double shuffle = runiform()
                
                .
                . //  MATCHING WITHOUT REPLACEMENT
                . sort case_DSCD year shuffle
                
                . local i = 1
                
                . while `i' < _N {
                  2.     drop if (case_DSCDS == case_DSCDS[`i'] | ctrl_DSCDS == ctrl_DSCDS[`i']) ///
                >         & year == year[`i'] in `=`i'+1'/L
                  3.     local ++i
                  4. }
                (4 observations deleted)
                (4 observations deleted)
                (4 observations deleted)
                (4 observations deleted)
                (4 observations deleted)
                (3 observations deleted)
                (3 observations deleted)
                (1 observation deleted)
                (2 observations deleted)
                (4 observations deleted)
                (4 observations deleted)
                (4 observations deleted)
                (4 observations deleted)
                (3 observations deleted)
                (4 observations deleted)
                (3 observations deleted)
                (3 observations deleted)
                (5 observations deleted)
                (4 observations deleted)
                (5 observations deleted)
                (4 observations deleted)
                (1 observation deleted)
                (0 observations deleted)
                (0 observations deleted)
                (0 observations deleted)
                (0 observations deleted)
                (0 observations deleted)
                (0 observations deleted)
                
                .
                . //  VERIFY EACH DSCDS GETS ONLY ONE MATCH IN EACH YEAR
                . isid case_DSCDS year
                
                .
                end of do-file
                I notice that in the code/output you show in #3, there is no output at all following the -while `i' < _N {- loop. Which means that somehow that loop wasn't being executed at all. I cannot think of a reason why that would happen, but that seems to be where it was going wrong for you. Notice the extensive output that loop generated here, which is where the extra pairings are being removed from the data set.

                Comment


                • #9
                  Hi Clyde Schechter, thanks for your response. Very strange that I don't get any output following the -while `i' < _N {- loop as you do. I can't seem to figure out how to get it to work. Any suggestions you can think of, or anything else I could post on my end that would help to figure out where I am going wrong, please let me know.

                  Thanks again for all your time and your kind assistance.

                  Best wishes,
                  Ammar.

                  Comment


                  • #10
                    The other thing I notice about that loop that is odd is that the line numbers appear on their own lines, above the commands they are supposed to correspond to. I have never seen Stata do this before. Compare to my output where the line numbers precede the commands on the same lines.

                    Particularly bizarre is the fact that a line number, 3., appears between - drop if (case_DSCD == case_DSCD[`i'] | ctrl_DSCD == ctrl_DSCD[`i']) /// - and - & year == year[`i'] in `=`i'+1'/L-. That means that Stata is somehow parsing that as two separate commands instead of a single command split between two lines. But that isn't really what's happening either, because having -& year == year[`i'] in `=`i'+1'/L- as a separate command would produce a syntax error and you would see the error message after the loop.

                    This sort of thing could happen if you were entering this code by typing it into the command window, which is not legal for this code, but, again, you would see an invalid syntax error message if that were what you are doing. So I'm stumped.

                    Comment


                    • #11
                      Hi Clyde Schechter , thanks for your response. You got my mistake. Using the do-file editor it works ok. I did get the invalid syntax and thought it was my mistake to add the final "}" in the code you originally shared and I assumed it wasn't part of the code but didn't affect the preceeding commands so ignored the error. My apologies for stumping you! Sorry, thanks for your time and lesson learned on my part.

                      Ammar.

                      Comment


                      • #12
                        Hi Clyde Schechter, Hope you are doing well.

                        I was running the codes that you have provided previously on this thread. However, I got an error when trying to 'rangejoin' the data.

                        The codes that I tried to run used the 1.1.1 version of 'rangestat'. However, the 1.1.0 version seemed to be required for the codes to run properly. I could not downgrade 'rangestat' from version 1.1.1 to version 1.1.0.

                        I was wondering whether you would have a solution to this problem or if not, alternative codes for matching data from a panel dataset.

                        Many thanks for your assistance.

                        Noor.

                        Comment


                        • #13
                          That is very strange. -rangestat- has been at version 1.1.1 since 2017. It is the version I have and it has never been a problem running -rangejoin- with it. I wonder if there is some other problem with the -rangejoin- command you issued and the error message is misleading about the nature of the problem. Or possibly something went wrong during the installation of one or both commands.

                          My first suggestion is reinstall both programs:
                          Code:
                          ssc install rangestat, replace
                          ssc install rangejoin, replace
                          If that doesn't solve the problem, then please post back with example data that demonstrates the problem (use -dataex- to show it) and also show the exact code you are using for the matching--do not edit or modify it in any way, there is no such thing as a minor change to code.

                          Comment


                          • #14
                            Hi Clyde Schechter. Thank you for your prompt reply.

                            I reinstalled both programs. However, this did not resolve the issue.

                            Please see the code used below:

                            Code:
                            xtset id year
                            
                            keep if gb!=. & assets!=. & industry_cat!=.
                            
                            tab gb
                            
                            
                            // PREPARE A CONTROLS FILE
                            preserve
                            keep if gb == 0
                            tempfile controls
                            save `controls'
                            
                            // PREPARE THE CASES
                            restore
                            keep if gb == 1
                            gen lb = 0.8*assets
                            gen ub = 1.2*assets
                            
                            // COMBINE THEM
                            rangejoin assets lb ub using `controls', by(year industry_cat) prefix(ctrl_)
                            ds year industry_cat lb ub ctrl_*, not
                            rename (`r(varlist)') case_=
                            
                            set seed 1234 //
                            gen double shuffle = runiform()
                            
                            // MATCHING WITH REPLACEMENT
                            by case_id year (shuffle), sort: keep if _n == 1

                            I want to match firms that are gb=1 (treatment firms) with firms that are gb=0 (controls). I received the below error message when running the codes:

                            Code:
                            . xtset id year
                            
                            Panel variable: id (strongly balanced)
                             Time variable: year, 2012 to 2022
                                     Delta: 1 unit
                            
                            . 
                            . keep if gb!=. & assets!=. & industry_cat!=.
                            (70,405 observations deleted)
                            
                            . 
                            . tab gb
                            
                                     gb |      Freq.     Percent        Cum.
                            ------------+-----------------------------------
                                      0 |     66,017       82.87       82.87
                                      1 |     13,651       17.13      100.00
                            ------------+-----------------------------------
                                  Total |     79,668      100.00
                            
                            . 
                            . 
                            . 
                            . //  PREPARE A CONTROLS FILE
                            . preserve
                            
                            . keep if gb == 0
                            (13,651 observations deleted)
                            
                            . tempfile controls
                            
                            . save `controls'
                            file C:\Users\noord\AppData\Local\Temp\ST_3bcc_000002.tmp saved as .dta format
                            
                            . 
                            . //  PREPARE THE CASES
                            . restore
                            
                            . keep if gb == 1
                            (66,017 observations deleted)
                            
                            . gen lb = 0.8*assets
                            
                            . gen ub = 1.2*assets
                            
                            . 
                            . //  COMBINE THEM
                            . rangejoin assets lb ub using `controls', by(year industry_cat) prefix(ctrl_)
                              (using rangestat version 1.1.1)
                            invalid syntax
                            r(198);
                            
                            end of do-file
                            
                            r(198);

                            Please see below the example data:

                            Code:
                            * Example generated by -dataex-. For more info, type help dataex
                            clear
                            input double id int year byte gb float(assets industry_cat)
                            4295856141 2012 1   1808804608 20
                            4295856141 2013 1   1417180928 20
                            4295856141 2014 1   1164325376 20
                            4295856141 2015 1   1268232448 20
                            4295856141 2016 1   1528969216 20
                            4295856141 2017 1   3951294720 20
                            4295856141 2018 1   8487993856 20
                            4295856141 2019 1   4938700288 20
                            4295856141 2020 1   4289188096 20
                            4295856141 2021 1   3579676928 20
                            4295856141 2022 1   2855337728 20
                            4295856152 2012 0 4.683916e+11 10
                            4295856152 2013 0 4.528087e+11 10
                            4295856152 2014 0 4.363746e+11 10
                            4295856152 2015 0 4.284631e+11 10
                            4295856152 2016 0 5.223855e+11 10
                            4295856152 2017 0 5.761167e+11 10
                            4295856152 2018 0 5.465368e+11 10
                            4295856152 2019 0 5.400683e+11 10
                            4295856152 2020 0 5.652704e+11 10
                            4295856152 2021 0 5.921452e+11 10
                            4295856152 2022 0 6.888321e+11 10
                            4295856585 2012 1  13927716864  8
                            4295856585 2013 1  13364715520  8
                            4295856585 2014 1  13347278848  8
                            4295856585 2015 1  12311232512  8
                            4295856585 2016 1  12814697472  8
                            4295856585 2017 1  13708691456  8
                            4295856585 2018 1  1.31146e+10  8
                            4295856585 2019 1  13227083776  8
                            4295856585 2020 1  21415759872  8
                            4295856585 2021 1  21276504064  8
                            4295856585 2022 1  18859759616  8
                            4295856605 2012 1 4.122348e+11 10
                            4295856605 2013 1 4.044899e+11 10
                            4295856605 2014 1 4.164804e+11 10
                            4295856605 2015 1 4.128005e+11 10
                            4295856605 2016 1 5.396811e+11 10
                            4295856605 2017 1 5.246895e+11 10
                            4295856605 2018 1 5.232833e+11 10
                            4295856605 2019 1 5.389201e+11 10
                            4295856605 2020 1 5.778718e+11 10
                            4295856605 2021 1 5.250316e+11 10
                            4295856605 2022 1 6.228374e+11 10
                            4295856627 2012 1 4.333162e+11 10
                            4295856627 2013 1 4.033978e+11 10
                            4295856627 2014 1 4.158061e+11 10
                            4295856627 2015 1 3.767372e+11 10
                            4295856627 2016 1 4.950451e+11 10
                            4295856627 2017 1 4.981132e+11 10
                            4295856627 2018 1 4.880031e+11 10
                            4295856627 2019 1 4.979926e+11 10
                            4295856627 2020 1 505607749632 10
                            4295856627 2021 1 5.019783e+11 10
                            4295856627 2022 1 5.818031e+11 10
                            4295857405 2012 1  4.89891e+11 10
                            4295857405 2013 1 4.659837e+11 10
                            4295857405 2014 1 4.764685e+11 10
                            4295857405 2015 1 4.430228e+11 10
                            4295857405 2016 1 4.581811e+11 10
                            4295857405 2017 1 4.609538e+11 10
                            4295857405 2018 1 4.474568e+11 10
                            4295857405 2019 1 4.653093e+11 10
                            4295857405 2020 1 4.804473e+11 10
                            4295857405 2021 1 4.966634e+11 10
                            4295857405 2022 1 6.052818e+11 10
                            4295858616 2012 1  30085074944 10
                            4295858616 2013 1  31227781120 10
                            4295858616 2014 1  28552157184 10
                            4295858616 2015 1  2.88963e+10 10
                            4295858616 2016 1  28617259008 10
                            4295858616 2017 1  33708843008 10
                            4295858616 2018 1  32461389824 10
                            4295858616 2019 1  31027537920 10
                            4295858616 2020 1  30290180096 10
                            4295858616 2021 1  34099394560 10
                            4295858616 2022 1  36442312704 10
                            4295858951 2012 1   4930173440 18
                            4295858951 2013 1   3801834752 18
                            4295858951 2014 1   3354550272 18
                            4295858951 2015 1   2851579392 18
                            4295858951 2016 1   2935689472 18
                            4295858951 2017 1   3667305728 18
                            4295858951 2018 1   4216821504 18
                            4295858951 2019 1   4814745088 18
                            4295858951 2020 1   4978644992 18
                            4295858951 2021 1   6092030976 18
                            4295858951 2022 1   5978039296 18
                            4295858953 2012 1  23817244672 10
                            4295858953 2013 1  24401084416 10
                            4295858953 2014 1  25737891840 10
                            4295858953 2015 1  25663969280 10
                            4295858953 2016 1  2.45363e+10 10
                            4295858953 2017 1  28668260352 10
                            4295858953 2018 1  25518856192 10
                            4295858953 2019 1  2.56257e+10 10
                            4295858953 2020 1  24242524160 10
                            4295858953 2021 1  28500881408 10
                            4295858953 2022 1  26508587008 10
                            4295858966 2012 1  11817740288 10
                            end
                            Many thanks for your assistance.

                            Noor

                            Comment


                            • #15
                              The code and data example you show in #14 runs without any error messages or interruptions on my setup, and it produces appropriate candidate matches.

                              I note that the error message you are saying is not about about the version of rangestat you are using. Where it says "(using rangestat version 1.1.1)" it is just providing you with that information, not complaining about it. The complaint is what comes next: "invalid syntax r(198);"

                              The problem is that you are running the code line-by-line or in chunks. The code contains a local macro `controls', which is defined in the -tempfile- and initialized in the -save- command. It is next mentioned in the -rangejoin- command. If execution is interrupted in between those, then the local macro `controls' goes out of scope. By the time you reach -rangejoin-, `controls' no longer exists, and Stata thinks you are asking it to run -rangejoin assets lb ub using, by(year industry_cat) prefix(ctrl_)-. That is, indeed, a syntax error because the -using- clause fails to mention a file to use.

                              So just run the code in one fell swoop from beginning to end. Or at least, don't interrupt it between -tempfile- and -rangejoin-, and you will get what you seek.

                              Comment

                              Working...
                              X