Calculate price elasticity of demand using historical price and sales data
harbor run -t snowflake-labs/dbt-price-elasticityharbor download snowflake-labs/dbt-price-elasticityThe pricing team is preparing for a major price adjustment: "We're thinking of raising prices on 200 SKUs but we have no idea how customers will react. Which products are price-sensitive? We need elasticity coefficients before we make a costly mistake."
Create a dbt model product_elasticity in schema elasticity_analytics that calculates price elasticity of demand for each product.
This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
/app/dbt_project/app/dbt_models_snowflakeelasticity_analytics (DuckDB) / main (Snowflake)You must configure dbt to connect to the database:
retail_dw_masterprofiles.yml in the dbt project directoryDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
(Hint: If your models appear in a different schema than expected, re-check your work and review how dbt handles schema naming when a custom schema is specified.)
Explore the database to find tables containing price history and order/sales data. You'll need to join data from the PRODUCT and ORDERS schemas to calculate price changes and corresponding quantity changes over time.
| Column | Description |
|---|---|
| product_id | Product identifier |
| elasticity_coefficient | Average elasticity (capped -10 to 10) |
| elasticity_type | elastic (abs > 1), inelastic (abs < 1), or unit_elastic (abs within 0.01 of 1) |
| num_observations | Number of valid period comparisons |
| avg_price | Average price across periods |
| avg_quantity | Average quantity across periods |
strftime() on DuckDB and TO_VARCHAR() on Snowflake