Skip to main content
Version: latest

Variable

The View Variable API provides detailed information about a specific statistical variable from BPS (Badan Pusat Statistik) Indonesia. Statistical variables represent specific measurable phenomena, indicators, or characteristics that are systematically collected, analyzed, and reported by BPS. They form the fundamental building blocks of statistical datasets.

Examples include Jumlah Penduduk (Population Count), Tingkat Partisipasi Angkatan Kerja (Labor Force Participation Rate), Produk Domestik Regional Bruto (GRDP), Indeks Harga Konsumen (Consumer Price Index), and Tingkat Kemiskinan (Poverty Rate).

Parameters

ParameterTypeDescription
idintRequired: The unique numerical identifier of the variable
domainStringRequired: The domain (region) code for the request
langDataLanguageOptional: Language preference (default: DataLanguage.id)

Examples

1. Basic Variable Retrieval

// Retrieve detailed information for a specific variable
final variable = await StadataFlutter.instance.view.variable(
id: 145,
domain: '0000', // National level
lang: DataLanguage.id,
);

if (variable != null) {
print('Variable ID: ${variable.id}');
print('Title: ${variable.title}');
print('Graph Name: ${variable.graphName}');
print('Unit: ${variable.unit}');
print('Subject ID: ${variable.subjectID}');
print('Subject Name: ${variable.subjectName}');
print('Notes: ${variable.notes}');
} else {
print('Variable not found');
}

2. Use Variable to Query Dynamic Table Data

// Get variable details then use it to query dynamic data
final variable = await StadataFlutter.instance.view.variable(
id: 145,
domain: '0000',
);

if (variable != null) {
print('Variable: ${variable.title} (${variable.unit})');
print('Vertical Variable ID: ${variable.verticalVariableID}');

// Get available periods for this variable
final periods = await StadataFlutter.instance.list.periods(
domain: '0000',
variableID: variable.id,
);

print('Available periods: ${periods.data.map((p) => p.year).join(', ')}');

// Fetch dynamic table data for the most recent period
if (periods.data.isNotEmpty) {
final latestPeriod = periods.data.first;
final tableData = await StadataFlutter.instance.view.dynamicTable(
variableID: variable.id,
domain: '0000',
period: '${latestPeriod.id}',
);

print('Data for ${latestPeriod.year}: ${tableData?.title}');
}
}

3. Inspect Variable Metadata

// Get full metadata for analysis
final variable = await StadataFlutter.instance.view.variable(
id: 200,
domain: '3200',
);

if (variable != null) {
print('=== Variable Metadata ===');
print('Title: ${variable.title}');
print('Graph Display Name: ${variable.graphName}');
print('Unit: ${variable.unit}');
print('Subject: ${variable.subjectName} (ID: ${variable.subjectID})');
print('Vertical Variable ID: ${variable.verticalVariableID}');

if (variable.csaSubjectName != null) {
print('CSA Subject: ${variable.csaSubjectName}');
}
if (variable.type != null) {
print('Type: ${variable.type}');
}
if (variable.derivedPeriodID != null) {
print('Derived Period ID: ${variable.derivedPeriodID}');
}
if (variable.derivedVariableID != null) {
print('Derived Variable ID: ${variable.derivedVariableID}');
}
print('\nMethodological Notes:');
print(variable.notes);
}

Error Handling

try {
final variable = await StadataFlutter.instance.view.variable(
id: 145,
domain: '0000',
lang: DataLanguage.id,
);

if (variable != null) {
print('Variable: ${variable.title}');
} else {
print('Variable not found');
}

} on VariableException catch (e) {
print('Variable error: ${e.message}');

} on ApiException catch (e) {
print('API error: ${e.message}');

} on ApiKeyNotFoundException catch (e) {
print('Authentication required: ${e.message}');

} catch (e) {
print('Unexpected error: $e');
}

Properties (Variable)

PropertyTypeDescription
idintUnique identifier for the statistical variable
titleStringOfficial full name of the statistical variable
graphNameStringShortened name optimized for display in charts and graphs
notesStringComprehensive methodological notes and variable definitions
unitStringUnit of measurement for the variable values
subjectIDintIdentifier of the statistical subject area this variable belongs to
subjectNameStringName of the statistical subject area containing this variable
verticalVariableIDintIdentifier linking to the associated vertical variable structure
csaSubjectNameString?Optional name of the cross-sectional subject classification
csaSubjectIDint?Optional identifier for the cross-sectional subject classification
typeint?Optional variable type classification code
derivedPeriodIDint?Optional identifier for derived time period calculations
derivedVariableIDint?Optional identifier for source variables in derived calculations