Announcement

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

  • Generate variable with multiple constraints

    Hi there,
    I am trying to generate these charge, outage and spillover variables.
    I have a battery with size 50 and it starts off fully charged. When net demand is negative it is charging the battery although it can't be charged over 50. When net demand is positive it discharges but can't go below 0. I can't seem to generate a charge variable that is the previous value less net demand constrained within 50>charge>0 let alone have it prompt an outage or spillover record. I have some example values below, thanks in advance!
    Net Demand Charge Outage Spillover
    -12 50 12
    -8 50 8
    12 38
    24 14
    15 0 -1
    -10 10
    -22 32
    -20 50 2

  • #2
    This may help.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(netdemand charge)
    -12 50
     -8 50
     12 38
     24 14
     15  0
    -10 10
    -22 32
    -20 50
    end
    
    gen wanted = 50 in 1
    replace wanted = cond(wanted[_n-1] - netdemand < 0, 0, min(50, wanted[_n-1] - netdemand)) in 2/L
    
    list, sep(0)
    
         +----------------------------+
         | netdem~d   charge   wanted |
         |----------------------------|
      1. |      -12       50       50 |
      2. |       -8       50       50 |
      3. |       12       38       38 |
      4. |       24       14       14 |
      5. |       15        0        0 |
      6. |      -10       10       10 |
      7. |      -22       32       32 |
      8. |      -20       50       50 |
         +----------------------------+

    Comment

    Working...
    X