← stock_to_flow operator page · time/stock_to_flow/date/manual_ex_2
pandas ✅ · DuckDB ✅
stock_to_flow(DS_2) on annual date series, where "conventionally each period is identified by its last day".
Stock to flow, Example 2, output verbatim: "for each time series, calculates the corresponding flow data by subtracting from the measure values of each regular period the corresponding measure values of the previous one."
The first value of each series, then the differences: A 2.0, 5.0, -3.0, 9.0 and B 4.0, -8.0, 0.0, 6.0.
DS_r := stock_to_flow ( DS_2 );
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-12-31 | 2.0 |
| A | 2011-12-31 | 7.0 |
| A | 2012-12-31 | 4.0 |
| A | 2013-12-31 | 13.0 |
| B | 2010-12-31 | 4.0 |
| B | 2011-12-31 | -4.0 |
| B | 2012-12-31 | -4.0 |
| B | 2013-12-31 | 2.0 |
{
"datasets": [
{
"name": "DS_2",
"DataStructure": [
{"name": "Id_1", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "Date", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Number", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Me_1 |
|---|---|---|
| A | 2010-12-31 | 2.0 |
| A | 2011-12-31 | 5.0 |
| A | 2012-12-31 | -3.0 |
| A | 2013-12-31 | 9.0 |
| B | 2010-12-31 | 4.0 |
| B | 2011-12-31 | -8.0 |
| B | 2012-12-31 | 0.0 |
| B | 2013-12-31 | 6.0 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "String", "role": "Identifier"},
{"name": "Id_2", "type": "Date", "role": "Identifier"},
{"name": "Me_1", "type": "Number", "role": "Measure"}
]
}
]
}