Greetings,
I'm running Stata 15.1 on OSX and working with panel data (2011, 2012, 2016, 2017, 2018). All of my variables are labeled according to the wave/year in which they were measured. To reshape the data from wide to long form, I entered the following syntax:
...which didn't work. The problem appears to be that certain variables are not available across all years. How can I correct for this?
Below is some sample data, which includes variables that either weren't included in the 2017 wave (immi_contribution_2018) or the 2016 and 2018 waves (immigration_cap_2017).
Thanks in advance for your help!
I'm running Stata 15.1 on OSX and working with panel data (2011, 2012, 2016, 2017, 2018). All of my variables are labeled according to the wave/year in which they were measured. To reshape the data from wide to long form, I entered the following syntax:
Code:
reshape long weight_ immi_contribution_ immi_naturalize_ immi_makedifficult_ immi_num_ immi_legal_ third_immi > _ europe_ mexico_ middleast_ india_ ideo5_ educ_ birthyr_ gender_ pew_religimp_ race_ weight_ pew_churatd_ re > vamshamed_ prouddem_ proudhis_ proudgrp_ race_deservemore_ race_overcome_ race_tryharder_ race_slave_ amborni > n_ amcit_ amlived_ amenglish_ amchrstn_ amgovt_ amwhite_ amdiverse_ race_importance_ race_majority_1_ race_ma > jority_2_ race_majority_3_ race_majority_4_ SOCIAL_CONFORMITY_1_ SOCIAL_CONFORMITY_2_ SOCIAL_CONFORMITY_3_ SO > CIAL_CONFORMITY_4_ immi_contribution_treat_ immi_contribution_a_ immi_contribution_b_ immigration_cap_ conta > ct_english_treat_ immigrants_take_ immigrants_culture_ immigrants_security_ immigrants_crime_ immigrants_econ > omy_ immigration_help_ volunteerorg2_10_ antieur_ egalitarian_opportunies_ egalitarian_worry_less_ egalitaria > n_no_big_deal_ egalitarian_fewer_problems_ faminc_ state_ party7_ case_identifier europe_ mexico_ middleast_ > india_ china_ africa_, i(case_identifier) j(year) (note: j = 2016 2017 2018) (note: immi_num_2016 not found) (note: immi_legal_2016 not found) (note: third_immi_2016 not found) (note: europe_2016 not found) (note: mexico_2016 not found) (note: middleast_2016 not found) (note: india_2016 not found) (note: birthyr_2016 not found) (note: gender_2016 not found) (note: immi_contribution_treat_2016 not found) (note: immi_contribution_a_2016 not found) (note: immi_contribution_b_2016 not found) (note: immigration_cap_2016 not found) (note: contact_english_treat_2016 not found) (note: immigrants_take_2016 not found) (note: immigrants_culture_2016 not found) (note: immigrants_security_2016 not found) (note: immigrants_crime_2016 not found) (note: immigrants_economy_2016 not found) (note: immigration_help_2016 not found) (note: volunteerorg2_10_2016 not found) (note: antieur_2016 not found) (note: egalitarian_opportunies_2016 not found) (note: egalitarian_worry_less_2016 not found) (note: egalitarian_no_big_deal_2016 not found) (note: egalitarian_fewer_problems_2016 not found) (note: case_identifier2016 not found) (note: china_2016 not found) (note: africa_2016 not found) variable weight_2016 not found r(111);
Below is some sample data, which includes variables that either weren't included in the 2017 wave (immi_contribution_2018) or the 2016 and 2018 waves (immigration_cap_2017).
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long case_identifier byte(immi_contribution_2016 immi_contribution_2018 immigration_cap_2017) 779 1 1 1 2108 2 3 2 2597 1 1 2 4148 1 . . 4460 3 2 2 5225 1 1 2 5903 1 . 2 6059 3 3 3 8048 1 . 1 9869 1 1 2 13112 1 . . 14087 1 1 2 14474 3 . 3 14507 1 1 2 15464 1 1 2 20459 1 1 2 25193 2 1 1 27599 3 8 2 2035940 1 1 1 6000479 3 . . 6000794 3 . 3 6001082 2 1 2 6002069 3 3 3 6004538 1 . 2 6006515 3 . 3 6008999 3 . 3 6009677 1 . . 6010778 1 1 2 6013199 3 3 3 6014066 2 . . 6014345 1 . . 6015176 3 3 3 6018461 3 . . 6020087 3 . . 6021503 1 . 2 6022898 3 3 2 6023987 3 . 2 6024683 8 3 3 6026186 1 1 2 6026195 1 1 1 6026246 1 1 2 6026537 3 . . 6028715 3 3 3 6032768 3 . . 6033338 3 3 3 6035645 8 . 2 6036608 1 . . 6038444 1 . . 6041060 3 . . 6046208 3 3 3 6048548 1 . . 6051575 1 . . 6054065 1 1 1 6057581 3 . . 6059078 3 . . 6061217 3 3 3 6061877 1 1 1 6061937 2 1 2 6062156 1 . . 6063833 1 1 2 6064967 1 1 1 6067322 2 1 2 6067754 3 3 1 6070919 3 . 3 6072560 1 1 1 6073346 1 1 2 6074072 3 2 2 6079028 1 . 2 6079631 1 . . 6081782 1 . 2 6082415 1 1 1 6082955 1 . . 6084239 1 . 2 6085712 3 3 3 6086672 3 . 3 6086936 1 . . 6088319 1 1 1 6088628 8 . 2 6089561 2 2 2 6095012 3 3 2 6095318 1 1 2 6095753 2 . 2 6095852 1 1 2 6098411 2 . . 6100238 1 1 2 6100907 3 3 3 6106253 3 . 3 6108272 1 1 1 6109619 1 1 2 6110054 1 2 2 6110435 1 1 1 6110906 3 3 1 6111152 3 . . 6112508 1 1 2 6114890 3 . . 6116483 3 . 3 6116600 1 . 2 6116972 1 . 2 6117203 1 . 1 6117347 1 1 2 end label values immi_contribution_2016 V323_A label def V323_A 1 "Mostly make a contribution", modify label def V323_A 2 "Neither", modify label def V323_A 3 "Mostly a drain", modify label def V323_A 8 "Don't know", modify label values immi_contribution_2018 V993_A label def V993_A 1 "Mostly make a contribution", modify label def V993_A 2 "Neither", modify label def V993_A 3 "Mostly a drain", modify label def V993_A 8 "Don't know", modify label values immigration_cap_2017 IMMIGRAT label def IMMIGRAT 1 "Increase", modify label def IMMIGRAT 2 "Keep about the same", modify label def IMMIGRAT 3 "Decrease", modify
Comment