Announcement

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

  • How to construct several transition matrices?

    Hi everyone,

    I have to construct several transition matrices. This is a quite new topic for me, so I apologize if I write something wrong. The idea is the following:
    1. Summarize all switches of contracts with a table that has each type of contract in the rows, and each type of contract in the columns. The matrix should give me the share of people that went from one contract to another when they change.
    2. Summarize all switches of contracts that change their contracted powers in period 1 only.
    3. I also want to the same thing, but with contract switches from a given contract into a contract when solar panels where installed (everything will be clearer below with a dataex).
    4. Finally, the idea is to save these matrices into tables that can be put into LaTeX please.
    Here is a dataex:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long(id sp_zipcode) double(date_contract_start date_contract_end) float kW_power_p1 str13 product_classification str5 tariff_ekon_id str19 fecha_operativa_pv long idcontrato float solar_dummy
    12201 28971 21581 22431 6.9 "Sin Sorpresas" "20DHA" ""                     307371 0
    12201 28971 22432 22523 6.9 "Sin Sorpresas" "20TD"  ""                    1105958 0
    12201 28971 22524 22645 6.9 "Sin Sorpresas" "20TD"  ""                    1403342 0
    12201 28971 22646 22676 6.9 "Sin Sorpresas" "20TD"  ""                    1615598 0
    12201 28971 22677 22735 6.9 "Sin Sorpresas" "20TD"  ""                    1894349 0
    12201 28971 22736 23010 6.9 "Sin Sorpresas" "20TD"  ""                    2329184 0
    12201 28971 23011 23069 6.9 "Sin Sorpresas" "20TD"  ""                    2951346 0
    12201 28971 23070     . 6.9 "Tarifa Justa"  "20TD"  ""                    3040052 0
    12204 28440 19738 21608 6.6 "Sin Sorpresas" "20DHA" "2022-07-29 16:10:00"   12204 1
    12204 28440 21609 21945 6.6 "Sin Sorpresas" "20DHA" "2022-07-29 16:10:00"  322750 1
    12204 28440 21946 22431 6.6 "Sin Sorpresas" "20DHA" "2022-07-29 16:10:00"  615892 1
    12204 28440 22432 22523 6.6 "Sin Sorpresas" "20TD"  "2022-07-29 16:10:00" 1223037 1
    end
    format %td date_contract_start
    format %td date_contract_end
    Here a short description of the dataset variables:
    1. -id- is the household’s ID,
    2. -kW_power_p1- is the contracted power in kW for period 1,
    3. -product_classification- is the contract type,
    4. -tariff_ekon_id- is the tariff type,
    5. -fecha_operativa_pv- is the date of the starting of panel solar’s use,
    6. -idcontrato- is the Contract ID,
    7. -solar_dummy- is a 0/1 dummy variable. 1 stands for the inclusion of a solar panel in a contract.
    Could you give me a hand with this, please?

    Your help is really appreciated... and needed!
    Thank you very much in advance.

    Best wishes,

    Michael
    Last edited by Michael Duarte Goncalves; 23 Nov 2023, 04:10.

  • #2
    have you looked at xttrans
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hi Maarten Buis:

      I was completely unaware of the existence of this command.
      I'll take a look at it and if I run into any problems, I'll come back to statalist again.

      Thanks for your suggestion!
      Have a nice day.

      Best,
      Michael

      Comment


      • #4
        Hi everyone again,

        It's the first time I use -xttrans-, and I am running into some problems.

        Basically, I declare -xtset- as a first option:

        Code:
        xtset idcontrato date_contract_start
        Then, I ran for example:

        Code:
        · xttrans kW_power_p1  if !missing(powers_tariff2_less_15000w )
        no observations
        
        · xttrans product_classification_encod if !missing(powers_tariff2_less_15000w )
        no observations
        
        · xttrans tariff_ekon_id_encod if !missing(powers_tariff2_less_15000w )
        no observations
        Could anyone give me an insight into why this is occurring, please?
        The idea is to look at when households ("id") change their contracts ("idcontrato"), what is the probability to observe this or that switch in contracted powers ("kW_power_p1"), in tariffs ("tariff_ekon_id"), etc.
        Here is a dataex:


        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input long(id sp_zipcode) double(date_contract_start date_contract_end) float kW_power_p1 long(product_classification_encod tariff_ekon_id_encod idcontrato) float solar_dummy
        74163 7010 20462 21608 3.45 3 2 93357 0
        31196 7600 20462 21608 3.45 3 2 93367 0
        27112 7400 20465 21608 5.75 3 2 93375 0
        17066 7310 20521 20971 5.75 3 2 93376 0
        36635 7518 20503 20517 5.75 3 2 93380 0
        44639 7570 20467 21608 5.75 3 2 93384 0
        35215 7590 20458 21608 5.75 3 2 93387 0
        33886 7530 20458 21608 5.75 3 2 93389 0
        17068 7340 20461 21608  4.6 3 2 93395 0
        35869 7670 20466 21608  9.2 1 2 93398 0
        30888 7340 20461 21274 5.75 1 2 93407 0
        22556 7620 20458 21307  4.6 1 2 93421 0
        27386 7011 20459 21608 3.45 3 2 93425 0
        15695 7141 20465 21608  6.9 3 2 93426 0
        end
        format %td date_contract_start
        format %td date_contract_end
        label values product_classification_encod product_classification_encod
        label def product_classification_encod 1 "Clasico", modify
        label def product_classification_encod 3 "Sin Sorpresas", modify
        label values tariff_ekon_id_encod tariff_ekon_id_encod
        label def tariff_ekon_id_encod 2 "20DHA", modify
        Thank you in advance.
        Michael
        Last edited by Michael Duarte Goncalves; 23 Nov 2023, 07:56.

        Comment


        • #5
          Could it be that I haven't any observations because my date_contract_start cannot be defined as a "Delta: 1 day"?
          Indeed, the contract start is not based on a daily basis...

          Code:
          . xtset idcontrato date_contract_start
          
          Panel variable: idcontrato (weakly balanced)
           Time variable: date_contract_start, 30may2011 to 15nov2023
                   Delta: 1 day
          I appreciate your help.
          Best,

          Michael

          Comment

          Working...
          X