Supplementary Code S1 - R/lavaan analysis scripts
Early Childhood Media Use and Family Context: Longitudinal Associations with
Problematic Media Use at Age 12

SOFTWARE
R version 4.4.3; lavaan version 0.7-2. Script 07 also requires the haven package
(and script 09 haven or readxl, depending on the input format).

CONTENTS
01  Fully adjusted and reduced ML-FIML path models: standardized coefficients,
    Wald 95% CIs, fit indices, likelihood-ratio test (Table 3, Table A1, Table S1)
02  Fully adjusted (primary) model: 5,000-resample bootstrap, percentile 95% CIs
    (Table 5)
03  Age-9 PMU sensitivity analysis: matched N = 1,389, fully adjusted
    specification, 5,000-resample bootstrap for the PMU9-augmented model
    (Table S2, Panel A)
04  Primary ML-FIML model compared with complete-case estimation
    (Table S4, Panel A)
05  Teacher-rated age-6 self-control sensitivity analysis, N = 1,203 subset
    (Table S2, Panel B)
06  Wave-13 longitudinal-weight sensitivity analysis, MLR with robust Wald CIs
    (Table S5)
07  Alternative age-6 device and age-9 activity composites, fully adjusted
    specification (Table S3)
08  Three-wave overlap, attrition comparisons, and minimal-information case
    sensitivity analyses (Table S6; Table S4, Panel B)
09  Availability audit of survey-weight, stratum, and PSU variables
    (metadata only; no model is fitted)
10  Age-9 media-use partial-response scoring sensitivity analysis
    (Table S4, Panel C)
11  Reduced model: 5,000-resample bootstrap, percentile 95% CIs
    (Section 3.7; Table S1; Appendix A, Table A1 note)

DATA ACCESS
No PSKC individual-level records are included in this archive. Access to PSKC
data is subject to the procedures of the Korea Institute of Child Care and
Education: https://panel.kicce.re.kr/

REPRODUCIBILITY SCOPE AND DATA PREPARATION
These scripts reproduce model fitting, reported model comparisons, sensitivity
checks, and the indicated inference procedures using prepared analysis files.
The source-to-analysis variable mapping and scoring rules are documented
below; preparing the input files requires authorized access to PSKC data.

The expected prepared input files are listed below. Variable names, data
types, missing-value markers, and the expected counts should be checked
before fitting models. The scripts use composites and standardized variables
prepared in SPSS and do not recreate the primary composites from
questionnaire items.

  FIML_with_PMU9_modelvars.csv                 scripts 01-04, 08, 11
  FIML_with_PMU9_and_TeacherSelfControl.csv    script 05
  PSKC_W13_FIML_Weighted_Model_Data.csv        script 06
  FIML_final.sav                               script 07 (item-level file)
  PSKC_W10_Age9_ItemCompleteness_Model.csv     script 10

Script 09 reads a PSKC wave-13 data or weight file; set SOURCE_FILE at the top
of the script to its path.

Variable names: Zmedia_age6 / Zmedia_age9 = standardized media-use frequency at
ages 6 and 9; Zpmu_age9 / Zpmu_age12 = standardized problematic media use at
ages 9 and 12; gender01 = child sex; Zmedu, Zfedu, Zincome = maternal education,
paternal education, household income; Zinter_age6 = parent-child interaction;
Zlowstress_age6 = lower parenting stress (reverse-scored); N_ID = PSKC child ID.
W13_weight_longitudinal (script 06) is the PSKC wave-13 longitudinal weight
DHu20wgh002.

VARIABLE DERIVATION AND SCORING CONVENTIONS (MANUSCRIPT SECTIONS 2.3-2.4)
- Zmedia_age6: mean frequency across four parent-reported device categories
  (computer/Internet, personal game console, phone/smartphone/tablet, TV),
  each rated 1-5, then z-standardized. All four valid item responses were
  required. In the available prepared SPSS analysis file (N = 2,150),
  1,524 children had all four responses and 626 had none; there were no
  partially completed four-item records (one to three valid responses).
  The stored unstandardized composite equaled the arithmetic mean of all
  four items in the 1,524 complete records. No index was calculated from
  partial responses. The main-model scripts consume the prepared z-score;
  they do not re-create it from individual questionnaire items.
- Zmedia_age9: mean of available responses across five parent-reported
  purposes of smartphone/computer use (learning, information seeking, gaming,
  entertainment, social networking), each rated 1-4, then z-standardized.
  At least one valid item was required: 1,362 observed composites included
  1,327 complete five-item responses and 35 with one to four valid items.
  Script 10 checks the alternative of treating those 35 composite scores as
  missing while retaining their other observed model variables under FIML.
- Zpmu_age12: mean of 15 mother-reported problematic-media-use items from
  wave 13, rated 1-4, with items 10 and 11 reverse-scored before averaging,
  then z-standardized. The 1,393 observed scores had all 15 valid items.
- Zpmu_age9: analogous 15-item age-9 PMU composite from wave 10, with items
  10 and 11 reverse-scored before averaging, then z-standardized; all 1,389
  observed composites had complete valid item sets. Used in script 03 only.
- Zinter_age6: mean of nine parent-reported shared-activity-frequency items,
  rated 1-4, then z-standardized. There were 1,565 complete nine-item scores;
  no partial item sets were present in the analysis data.
- Zlowstress_age6: mean of eleven mother-reported parenting-stress items,
  rated 1-5; the composite was reverse-coded so higher scores mean LOWER
  parenting stress, then z-standardized. The 1,565 observed composites had
  complete eleven-item responses. The manuscript's descriptive Table 1
  reports parenting stress in its original, higher-stress direction.
- gender01: 0 = male, 1 = female (binary indicator, not z-standardized).
- Zincome: wave-7 monthly household income, originally reported in units of
  10,000 Korean won, treated as continuous and z-standardized.
- Zmedu and Zfedu: wave-7 maternal and paternal education, respectively,
  each on a seven-category ordered scale (higher = more education), treated
  as continuous and z-standardized.
- Teacher-rated age-6 self-control (script 05 only): mean of seven K-SSRS
  items (3, 5, 6, 11, 13, 14, 20), rated 1-3, with complete-item scores for
  the N = 1,203 teacher-rating subset. Consult script 05 for the exact
  prepared-variable name used by that analysis.
- N_ID: child identifier used to validate unique records in scripts that
  require it; it is not a covariate in the primary model.

OFFICIAL PSKC CODEBOOK-TO-ANALYSIS VARIABLE CROSSWALK
Source: PSKC codebook, version 251226 (December 2025; file "[한국아동패널]
업로드용 코드북_251226"), worksheets "2014_7차" (wave 7), "2017_10차" (wave 10),
and "2020_13차" (wave 13), column "수정 변수명" (revised variable name).
These are official variable identifiers in that codebook. Analysis-file
names and composite variables are user-prepared, not official PSKC codes.
The mapping identifies source questionnaire fields based
on their codebook descriptions; the raw-data-to-analysis transformation script
is not part of this archive. Check original response coding and missing-value
rules against the PSKC codebook when recreating datasets.

Primary model variable | Wave | Official PSKC variable(s) | Derivation
-----------------------|------|---------------------------|-----------
Zmedia_age6 | 7 (2014) | DCh14mid001, DCh14mid002, DCh14mid003, DCh14mid007 | mean of 4 device-use frequency items; require all 4; then z-score
Zmedia_age9 | 10 (2017) | DCh17mid015a, DCh17mid015b, DCh17mid015c, DCh17mid015d, DCh17mid015e | mean of 5 purpose-frequency items, allowing available items; then z-score
Zpmu_age12 | 13 (2020) | DCh20mid018-DCh20mid032 (15 items) | reverse items 10 and 11; item mean; then z-score
Zinter_age6 | 7 (2014) | EMt14crs026-EMt14crs034 (9 items) | item mean; then z-score
Zlowstress_age6 | 7 (2014) | EMt14prs001-EMt14prs011 (11 items) | item mean, reverse direction to LOWER stress; then z-score
gender01 | 7 (2014) | DCh14dmg001 | sex recoded as 0=male, 1=female
Zincome | 7 (2014) | DHu14ses006 | monthly household income (10,000 KRW); then z-score
Zmedu | 7 (2014) | DMt14dmg014 | maternal highest education; then z-score
Zfedu | 7 (2014) | DFt14dmg014 | paternal highest education; then z-score

Component-level item mapping (codebook labels paraphrased):
- Age 6 media (7th wave): DCh14mid001 = computer/Internet;
  DCh14mid002 = game console; DCh14mid003 = mobile phone;
  DCh14mid007 = television. In the prepared FIML_final.sav file, the
  corresponding working item names are MEDIA6_P, MEDIA6_G, V28_A,
  and MEDIA6_T, respectively. Their prepared mean is MEDIA_AG, whose
  standardized version is ZMEDIA_A; primary CSV models use Zmedia_age6.
- Age 9 media (10th wave): DCh17mid015a = learning;
  DCh17mid015b = information search; DCh17mid015c = gaming;
  DCh17mid015d = entertainment; DCh17mid015e = social networking.
- Age 12 PMU (13th wave, mother's assessment):
  DCh20mid018, DCh20mid019, DCh20mid020, DCh20mid021, DCh20mid022,
  DCh20mid023, DCh20mid024, DCh20mid025, DCh20mid026, DCh20mid027,
  DCh20mid028, DCh20mid029, DCh20mid030, DCh20mid031, DCh20mid032.
  Items 10 and 11 correspond to DCh20mid027 and DCh20mid028.
- Age 6 parent-child interaction (7th wave, mother's questionnaire):
  EMt14crs026, EMt14crs027, EMt14crs028, EMt14crs029, EMt14crs030,
  EMt14crs031, EMt14crs032, EMt14crs033, EMt14crs034.
- Age 6 maternal parenting stress (7th wave):
  EMt14prs001, EMt14prs002, EMt14prs003, EMt14prs004, EMt14prs005,
  EMt14prs006, EMt14prs007, EMt14prs008, EMt14prs009, EMt14prs010,
  EMt14prs011. Do not substitute the separate paternal FFt14prs items.

Sensitivity-only variable source mapping:
- Zpmu_age9 (10th wave, mother-rated child PC/smartphone problematic use):
  ECh17mid018-ECh17mid032 (15 items); reverse items 10 and 11
  (ECh17mid027, ECh17mid028), then calculate the mean and z-score.
- Teacher-rated age-6 self-control (7th wave, seven K-SSRS items):
  HIn14ssr003, HIn14ssr005, HIn14ssr006, HIn14ssr011,
  HIn14ssr013, HIn14ssr014, HIn14ssr020.
  These are teacher ('교사') codes; do not substitute mother-reported
  ICh14ssr codes with a similar subscale label.

STANDARDIZATION
Continuous composite and socioeconomic variables were standardized as z scores
in SPSS before the R analyses; the SPSS syntax for this step is not included,
and the supplied scripts use the prepared values. For the same observations
and model specification, fully standardized (std.all) path coefficients are
unchanged by linear z-score transformations of continuous variables. The sex
indicator remained coded 0/1 and was not standardized before model fitting.

MISSING-DATA AND SAMPLE RULES
- Missing or nonvalid source item responses must be represented as missing,
  not as substantive item values. Script 07 explicitly limits device items
  to 1-5 and age-9-purpose items to 1-4 and uses all nine observed items
  for its common-subset alternative-composite comparisons (Table S3).
- For prepared CSV files, primary scripts typically recognize blank cells,
  NA, NaN, and #NULL! as missing. Check import rules in each script, since
  not all scripts use identical read.csv arguments. Prepared datasets should
  use conventional blank/NA missing values consistently.
- Primary analysis: N = 2,150 rows, nine model variables, ML estimation and
  FIML for missing observations; fixed.x = FALSE allows cases with missing
  exogenous covariates to contribute through the joint model. FIML does NOT
  impute completed questionnaire item scores or validate MAR.
- Complete-case sensitivity (script 04): only rows complete on all nine
  primary model variables (n = 1,082).
- PMU9 sensitivity (script 03): observed PMU9 subset (n = 1,389); both models
  use this same subset, with FIML for other model variables.
- Self-control sensitivity (script 05): teacher-rated self-control subset
  (n = 1,203), with the paired models evaluated in that subset.
- Script 08 documents three-wave overlap and sensitivity to minimally
  informative records. Do not reinterpret N = 2,150 as the number with
  observed data at all three focal ages.
- Script 06 uses a wave-13 longitudinal weight; it does not incorporate
  original stratum or PSU clustering, and neither do the bootstrap scripts.

ANALYSIS SETTINGS
- All path models: estimator = 'ML' (script 06: 'MLR'), missing = 'fiml',
  fixed.x = FALSE, meanstructure = TRUE, with all covariances among exogenous
  variables freely estimated.
- Coefficients are fully standardized (std.all). Unless stated otherwise,
  CIs are Wald (delta-method) intervals.
- Bootstrap analyses (scripts 02, 03, 11) use 5,000 attempted ordinary
  (nonparametric) resamples of the FIML model; percentile CIs are computed
  from the finite (valid) bootstrap estimates, and the number of valid
  draws is reported.
- Seeds: script 02 uses iseed = 2026110400 + block; script 11 uses
  iseed = 2026111100 + block; script 03 uses set.seed(20261110).
- Scripts 02 and 11 save draws in blocks of 100 (.rds files). If block files
  are present in the working directory they are reloaded; otherwise all
  blocks are computed. Block files are not included in this archive.
- Script 06 applies sampling weights only; the original PSKC strata and PSU
  clustering could not be incorporated (see manuscript Sections 3.7 and 4.1).

Reduced-model bootstrap results (script 11; 5,000/5,000 valid draws):
  indirect beta = .019628, percentile 95% CI [.008796, .032754]
  total    beta = .054864, percentile 95% CI [.000436, .108806]

RUNNING THE SCRIPTS
Run each script from a working directory that contains its input file, e.g.
  source('02_Primary_5000_Bootstrap.R', encoding = 'UTF-8')
Scripts 02, 03, and 11 (5,000 bootstrap resamples each) can take a long time.
