BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Hello,

 

I have a repeated-measures long-form dataset where each person (Subject) has more than one row of data (i.e., long-form data) with the time point indicated by the variable date. The dataset has the following between-person variables: gender, age, and Has_Depr_or_Anxiety (they are the same within each subject). Light_Phys_Act (light physical activity) and Depression_Score are measured at each date per person (they vary at each time point per person). Light_Phys_Act_Between represents the mean light physical activity per person and is also a between-person variable. Light_Phys_Act_Within represents a subject's deviation from their own overall mean at a given date (i.e., Light_Phys_Act - Light_Phys_Act_Between). Below is a sample of my data (about 5%):

 

Data PA_MH;
Input Subject date date12. gender age Light_Phys_Act Light_Phys_Act_Between Light_Phys_Act_Within Depression_Score Has_Depr_or_Anxiety;
datalines;
315	05Jan2020	0	67	5.1167	4.88036	0.23631	4	1
315	04Feb2020	0	67	4.8	4.88036	-0.08036	3	1
315	05Mar2020	0	67	4.9571	4.88036	0.07678	2	1
315	04Apr2020	0	67	5.0607	4.88036	0.18035	0	1
315	04May2020	0	67	4.9154	4.88036	0.03502	2	1
315	03Jun2020	0	67	4.9071	4.88036	0.02678	0	1
315	03Jul2020	0	67	5.0625	4.88036	0.18214	0	1
315	03Aug2020	0	67	4.6628	4.88036	-0.21754	2	1
315	01Sep2020	0	67	4.6403	4.88036	-0.24008	1	1
315	01Oct2020	0	67	4.9036	4.88036	0.02321	2	1
315	31Oct2020	0	67	4.7238	4.88036	-0.15655	1	1
315	30Nov2020	0	67	4.8143	4.88036	-0.06607	2	1
322	11Jan2020	1	47	7.35	6.51667	0.83333	1	0
322	16Mar2020	1	47	5.6833	6.51667	-0.83333	0	0
328	13Jan2020	1	26	6.2133	6.97072	-0.75739	7	1
328	12Feb2020	1	26	7.2346	6.97072	0.2639	1	1
328	13Mar2020	1	26	7.269	6.97072	0.29833	0	1
328	12Apr2020	1	26	5.7528	6.97072	-1.21794	2	1
328	12May2020	1	26	7.7125	6.97072	0.74178	0	1
328	12Jun2020	1	26	6.5896	6.97072	-0.38114	0	1
328	12Jul2020	1	26	7.3394	6.97072	0.36867	0	1
328	11Aug2020	1	26	6.5704	6.97072	-0.40035	0	1
328	10Sep2020	1	26	7.8333	6.97072	0.86261	2	1
328	09Oct2020	1	26	7.5167	6.97072	0.54595	0	1
328	09Nov2020	1	26	6.6463	6.97072	-0.32442	0	1
361	14Jan2020	1	27	6.0667	5.99167	0.075	3	1
361	13Feb2020	1	27	5.9167	5.99167	-0.075	0	1
369	12Jan2020	0	28	7.72	7.56925	0.15075	6	1
369	11Feb2020	0	28	7.2769	7.56925	-0.29232	7	1
369	15Mar2020	0	28	8.0167	7.56925	0.44742	4	1
369	11Apr2020	0	28	7.7063	7.56925	0.137	9	1
369	11May2020	0	28	7.3619	7.56925	-0.20734	6	1
369	10Jun2020	0	28	7.0056	7.56925	-0.56369	9	1
369	13Jul2020	0	28	6.7	7.56925	-0.86925	9	1
369	07Nov2020	0	28	8.7667	7.56925	1.19742	8	1
398	18Jan2020	0	54	8.1139	8.00964	0.10425	3	1
398	17Feb2020	0	54	8.3583	8.00964	0.34869	1	1
398	18Mar2020	0	54	8.1405	8.00964	0.13083	0	1
398	18Apr2020	0	54	8.0833	8.00964	0.07369	4	1
398	17May2020	0	54	8.3756	8.00964	0.366	3	1
398	17Jun2020	0	54	7.5731	8.00964	-0.43656	4	1
398	16Jul2020	0	54	8.2762	8.00964	0.26655	0	1
398	15Aug2020	0	54	7.6798	8.00964	-0.32988	1	1
398	14Sep2020	0	54	8.1381	8.00964	0.12845	2	1
398	14Oct2020	0	54	8.2714	8.00964	0.26179	2	1
398	13Nov2020	0	54	7.0958	8.00964	-0.91381	5	1
484	18Jan2020	0	28	7.43	7.19115	0.23885	22	1
484	17Feb2020	0	28	7.5013	7.19115	0.31014	18	1
484	20Mar2020	0	28	6.8833	7.19115	-0.30781	17	1
484	17Jun2020	0	28	5.53	7.19115	-1.66115	20	1
484	16Aug2020	0	28	8.6111	7.19115	1.41997	24	1
498	20Jan2020	0	31	7.1361	6.86973	0.26638	4	1
498	18Feb2020	0	31	7.5205	6.86973	0.65078	2	1
498	19Mar2020	0	31	6.5636	6.86973	-0.30609	3	1
498	18Apr2020	0	31	7.097	6.86973	0.22724	0	1
498	19May2020	0	31	7.5119	6.86973	0.64217	2	1
498	18Jun2020	0	31	7.359	6.86973	0.48924	6	1
498	19Jul2020	0	31	4.9	6.86973	-1.96973	1	1
521	21Jan2020	0	48	7.4889	7.43784	0.05105	6	1
521	20Feb2020	0	48	7.1476	7.43784	-0.29022	7	1
521	21Mar2020	0	48	7.2155	7.43784	-0.22237	6	1
521	20Apr2020	0	48	7.6536	7.43784	0.21573	7	1
521	20May2020	0	48	7.5024	7.43784	0.06454	6	1
521	23Jun2020	0	48	7.7452	7.43784	0.3074	8	1
521	19Jul2020	0	48	7.731	7.43784	0.29311	6	1
521	18Aug2020	0	48	7.306	7.43784	-0.13189	4	1
521	17Sep2020	0	48	7.2643	7.43784	-0.17356	5	1
521	17Oct2020	0	48	7.8119	7.43784	0.37406	5	1
521	16Nov2020	0	48	6.95	7.43784	-0.48784	5	1
525	04Feb2020	1	62	6.9333	7.27262	-0.33929	5	1
525	09Mar2020	1	62	7.4631	7.27262	0.19048	5	1
525	09Apr2020	1	62	7.6298	7.27262	0.35714	8	1
525	04May2020	1	62	7.4476	7.27262	0.175	5	1
525	06Jun2020	1	62	7.4524	7.27262	0.17976	4	1
525	03Jul2020	1	62	7.1786	7.27262	-0.09405	4	1
525	04Aug2020	1	62	7.219	7.27262	-0.05357	3	1
525	04Sep2020	1	62	7.0917	7.27262	-0.18095	5	1
525	02Oct2020	1	62	7.3417	7.27262	0.06905	3	1
525	06Nov2020	1	62	6.969	7.27262	-0.30357	5	1
549	06Feb2020	0	32	7.387	7.51895	-0.13191	6	1
549	03Mar2020	0	32	7.5782	7.51895	0.05926	4	1
549	07Apr2020	0	32	7.2936	7.51895	-0.22536	4	1
549	07May2020	0	32	7.6333	7.51895	0.11439	7	1
549	04Jun2020	0	32	7.7026	7.51895	0.18362	5	1
554	06Feb2020	0	32	5.7889	5.43442	0.35447	2	1
554	05Mar2020	0	32	5.5107	5.43442	0.0763	4	1
554	05Apr2020	0	32	5.9488	5.43442	0.51439	6	1
554	04May2020	0	32	6.8452	5.43442	1.41082	10	1
554	03Jun2020	0	32	5.9476	5.43442	0.5132	8	1
554	04Jul2020	0	32	6.3486	5.43442	0.91419	9	1
554	02Sep2020	0	32	5.4348	5.43442	0.00043	7	1
554	01Oct2020	0	32	3.7444	5.43442	-1.68997	9	1
554	31Oct2020	0	32	4.6917	5.43442	-0.74275	6	1
554	30Nov2020	0	32	4.0833	5.43442	-1.35108	6	1
633	06Feb2020	0	43	7.5444	7.07521	0.46923	1	0
633	07Mar2020	0	43	7.2167	7.07521	0.14145	0	0
633	07Apr2020	0	43	7.4833	7.07521	0.40812	1	0
633	07May2020	0	43	7.4	7.07521	0.32479	0	0
633	06Jun2020	0	43	7.2786	7.07521	0.20336	0	0
633	07Jul2020	0	43	7.2131	7.07521	0.13788	0	0
633	06Aug2020	0	43	7.2512	7.07521	0.17598	0	0
633	03Sep2020	0	43	6.3071	7.07521	-0.76807	0	0
633	03Oct2020	0	43	6.8615	7.07521	-0.21368	0	0
633	01Nov2020	0	43	6.1962	7.07521	-0.87906	0	0
652	10Feb2020	0	29	7.5233	7.32782	0.19552	4	1
652	17Mar2020	0	29	7.5015	7.32782	0.1737	10	1
652	11Apr2020	0	29	7.3545	7.32782	0.02673	0	1
652	15May2020	0	29	7.2667	7.32782	-0.06115	6	1
652	14Jun2020	0	29	7.2042	7.32782	-0.12365	6	1
652	10Aug2020	0	29	7.1167	7.32782	-0.21115	8	1
656	10Feb2020	1	57	7.9333	7.93333	0	4	1
676	21Feb2020	0	55	8.98	8.98	0	9	1
682	27Feb2020	0	45	6.775	6.4481	0.3269	3	1
682	27Mar2020	0	45	6.6131	6.4481	0.165	4	1
682	26Apr2020	0	45	6.2179	6.4481	-0.23024	2	1
682	25May2020	0	45	7.1881	6.4481	0.74	0	1
682	25Jun2020	0	45	6.394	6.4481	-0.05405	6	1
682	26Jul2020	0	45	5.8286	6.4481	-0.61952	2	1
682	28Aug2020	0	45	6.3369	6.4481	-0.11119	2	1
682	27Sep2020	0	45	6.2012	6.4481	-0.2469	3	1
682	26Oct2020	0	45	6.3464	6.4481	-0.10167	5	1
682	26Nov2020	0	45	6.5798	6.4481	0.13167	3	1
710	19Feb2020	0	34	6.2733	5.74452	0.52881	10	1
710	20Apr2020	0	34	5.1095	5.74452	-0.635	10	1
710	26May2020	0	34	5.6833	5.74452	-0.06119	2	1
710	19Aug2020	0	34	5.9119	5.74452	0.16738	5	1
722	19Jul2020	1	84	6.7361	6.72185	0.01426	2	0
722	19Aug2020	0	59	6.555	6.72185	-0.16685	3	0
722	18Sep2020	0	59	6.9952	6.72185	0.27339	3	0
722	18Oct2020	0	59	6.2655	6.72185	-0.45637	3	0
722	22Nov2020	0	59	7.0574	6.72185	0.33556	2	0
776	19Feb2020	1	59	8.32	8.08995	0.23005	5	1
776	21Mar2020	1	59	7.4595	8.08995	-0.63043	8	1
776	20Apr2020	1	59	8.1202	8.08995	0.03029	7	1
776	19May2020	1	59	8.2905	8.08995	0.20052	7	1
776	18Jun2020	1	59	8.2595	8.08995	0.16957	5	1
793	01Mar2020	1	26	6.3067	7.06377	-0.75711	6	1
793	31Mar2020	1	26	7.6119	7.06377	0.54813	10	1
793	02May2020	1	26	7.594	7.06377	0.53028	6	1
793	30May2020	1	26	6.4083	7.06377	-0.65544	7	1
793	29Jun2020	1	26	6.8611	7.06377	-0.20266	3	1
793	29Jul2020	1	26	7.0167	7.06377	-0.04711	7	1
793	29Sep2020	1	26	7.7296	7.06377	0.66586	7	1
793	28Oct2020	1	26	6.9818	7.06377	-0.08195	8	1
804	22Mar2020	0	26	8.5267	8.52667	0	6	1
806	11Mar2020	0	37	7.1361	7.93797	-0.80186	5	1
806	10Apr2020	0	37	7.847	7.93797	-0.091	4	1
806	10May2020	0	37	7.8667	7.93797	-0.07131	8	1
806	09Jun2020	0	37	8.2524	7.93797	0.31441	4	1
806	09Jul2020	0	37	8.0208	7.93797	0.08286	6	1
806	14Aug2020	0	37	8.3179	7.93797	0.37988	7	1
806	10Sep2020	0	37	8.125	7.93797	0.18703	11	1
849	01Apr2020	1	62	7.3233	7.39885	-0.07551	0	0
849	01May2020	1	62	7.4595	7.39885	0.06068	0	0
849	31May2020	1	62	7.4917	7.39885	0.09282	0	0
849	30Jun2020	1	62	7.2298	7.39885	-0.16909	0	0
849	30Jul2020	1	62	7.3	7.39885	-0.09885	1	0
849	29Aug2020	1	62	7.3393	7.39885	-0.05956	0	0
849	28Sep2020	1	62	7.4282	7.39885	0.02936	0	0
849	28Oct2020	1	62	7.4631	7.39885	0.06425	0	0
849	27Nov2020	1	62	7.5548	7.39885	0.15591	0	0
896	08Apr2020	1	55	6.01	6.20309	-0.19309	1	0
896	09May2020	1	55	6.3987	6.20309	0.19563	1	0
896	09Jun2020	1	55	6.3931	6.20309	0.18996	0	0
896	08Jul2020	1	55	6.3817	6.20309	0.17858	0	0
896	06Aug2020	1	55	5.8167	6.20309	-0.38642	1	0
896	05Oct2020	1	55	6.1278	6.20309	-0.07531	1	0
896	05Nov2020	1	55	6.2938	6.20309	0.09066	0	0
934	08Apr2020	1	68	6.8	6.77413	0.02587	0	0
934	08May2020	1	68	6.2667	6.77413	-0.50747	0	0
934	07Jun2020	1	68	6.8417	6.77413	0.06753	0	0
934	07Jul2020	1	68	6.7262	6.77413	-0.04794	0	0
934	06Aug2020	1	68	7.8597	6.77413	1.08559	0	0
934	05Sep2020	1	68	6.619	6.77413	-0.15508	0	0
934	05Oct2020	1	68	6.4798	6.77413	-0.29437	0	0
934	04Nov2020	1	68	6.6	6.77413	-0.17413	0	0
940	07Apr2020	1	45	6.75	4.12282	2.62718	0	0
940	07May2020	1	45	5.6385	4.12282	1.51564	1	0
940	06Jun2020	1	45	3.8262	4.12282	-0.29663	2	0
940	07Jul2020	1	45	3.5742	4.12282	-0.54858	0	0
940	06Aug2020	1	45	3.6167	4.12282	-0.50615	0	0
940	04Sep2020	1	45	3.3192	4.12282	-0.80359	0	0
940	05Oct2020	1	45	3.2444	4.12282	-0.87838	0	0
940	04Nov2020	1	45	3.0133	4.12282	-1.10949	0	0
945	13Apr2020	0	45	7.6333	7.63333	0	7	1
952	11Apr2020	1	35	1.575	1.47083	0.10417	8	1
952	12May2020	1	35	1.3667	1.47083	-0.10417	14	1
1061	18Apr2020	0	62	7.5917	8.1013	-0.50964	1	1
1061	18May2020	0	62	8.6131	8.1013	0.51179	4	1
1061	17Jun2020	0	62	7.806	8.1013	-0.29535	2	1
1061	17Jul2020	0	62	8.1192	8.1013	0.01793	5	1
1061	17Aug2020	0	62	7.7524	8.1013	-0.34892	2	1
1061	18Sep2020	0	62	8.4167	8.1013	0.31536	1	1
1061	20Oct2020	0	62	8.0769	8.1013	-0.02438	1	1
1061	15Nov2020	0	62	8.4345	8.1013	0.33322	4	1
1082	21Apr2020	1	37	5.931	6.29277	-0.36182	0	1
1082	20May2020	1	37	5.9872	6.29277	-0.30559	2	1
1082	18Jun2020	1	37	6.7897	6.29277	0.49698	1	1
1082	18Jul2020	1	37	6.3897	6.29277	0.09698	5	1
1082	24Aug2020	1	37	6.565	6.29277	0.27223	7	1
1082	17Sep2020	1	37	5.8024	6.29277	-0.49039	1	1
1082	22Oct2020	1	37	6.3681	6.29277	0.07529	1	1
1082	18Nov2020	1	37	6.5091	6.29277	0.21632	2	1
1089	19Apr2020	0	66	7.5933	7.22275	0.37058	0	1
1089	19May2020	0	66	7.1439	7.22275	-0.07882	1	1
1089	19Jun2020	0	66	7.4264	7.22275	0.20363	0	1
1089	18Aug2020	0	66	6.4042	7.22275	-0.81859	1	1
1089	23Sep2020	0	66	7.3359	7.22275	0.11314	1	1
1089	16Oct2020	0	66	7.4861	7.22275	0.26336	1	1
1089	18Nov2020	0	66	7.1694	7.22275	-0.05331	2	1
1118	18Apr2020	0	41	8.2833	8.66301	-0.37968	0	0
1118	19May2020	0	41	8.481	8.66301	-0.18206	1	0
1118	17Jun2020	0	41	8.9879	8.66301	0.32487	0	0
1118	17Jul2020	0	41	9.113	8.66301	0.44995	0	0
1118	16Aug2020	0	41	8.8013	8.66301	0.13827	0	0
1118	15Sep2020	0	41	8.9639	8.66301	0.30088	0	0
1118	15Oct2020	0	41	8.481	8.66301	-0.18206	1	0
1118	14Nov2020	0	41	8.1929	8.66301	-0.47016	0	0
1152	26Apr2020	1	29	7.0367	7.47718	-0.44051	0	0
1152	25May2020	1	29	7.6036	7.47718	0.1264	0	0
1152	25Jun2020	1	29	7.5167	7.47718	0.03949	0	0
1152	24Jul2020	1	29	8.0238	7.47718	0.54663	0	0
1152	24Aug2020	1	29	7.7924	7.47718	0.31525	0	0
1152	22Sep2020	1	29	6.8722	7.47718	-0.60495	0	0
1152	21Nov2020	1	29	7.4949	7.47718	0.0177	0	0
1174	25Apr2020	1	22	6.331	6.83288	-0.50193	24	1
1174	26May2020	1	22	6.7321	6.83288	-0.10083	13	1
1174	28Jun2020	1	22	7.1667	6.83288	0.33379	13	1
1174	22Jul2020	1	22	7.0792	6.83288	0.24629	14	1
1174	27Aug2020	1	22	6.8556	6.83288	0.02268	9	1
1200	07May2020	0	34	9.0125	9.0125	0	4	0
1202	28Nov2020	1	26	7.0512	7.05119	0	10	1
1228	04May2020	1	60	8.425	8.05045	0.37455	0	0
1228	02Jun2020	1	60	7.8512	8.05045	-0.19926	0	0
1228	02Jul2020	1	60	7.9515	8.05045	-0.09893	0	0
1228	04Aug2020	1	60	8.1704	8.05045	0.11992	0	0
1228	03Sep2020	1	60	7.8542	8.05045	-0.19628	0	0
1233	30May2020	1	81	10.0028	8.35913	1.64364	1	1
1233	05Jul2020	1	81	7.3694	8.35913	-0.98969	4	1
1233	30Jul2020	1	81	8.7119	8.35913	0.35277	4	1
1233	29Aug2020	1	81	7.4397	8.35913	-0.91939	4	1
1233	28Oct2020	1	81	8.2718	8.35913	-0.08734	5	1
1238	02May2020	1	31	5.169	5.75817	-0.58913	1	0
1238	02Aug2020	1	31	5.2167	5.75817	-0.54151	1	0
1238	04Sep2020	1	31	5.875	5.75817	0.11683	1	0
1238	28Sep2020	1	31	6.3417	5.75817	0.58349	1	0
1238	27Oct2020	1	31	5.95	5.75817	0.19183	0	0
1238	26Nov2020	1	31	5.9967	5.75817	0.23849	2	0
1256	13May2020	1	41	6.1472	6.61111	-0.46389	1	0
1256	13Jun2020	1	41	6.2333	6.61111	-0.37778	2	0
1256	14Jul2020	1	41	7.4528	6.61111	0.84167	1	0
1276	19May2020	1	45	7.5167	7.65694	-0.14028	1	0
1276	19Jun2020	1	45	7.7972	7.65694	0.14028	0	0
1289	19May2020	0	42	7.83	7.982	-0.152	0	0
1289	17Jun2020	0	42	7.9595	7.982	-0.02247	0	0
1289	22Jul2020	0	42	8.1051	7.982	0.12313	0	0
1289	21Aug2020	0	42	8.0333	7.982	0.05134	0	0
1299	19May2020	0	55	6.3389	6.54958	-0.21069	6	1
1299	21Jun2020	0	55	3.9083	6.54958	-2.64125	5	1
1299	18Jul2020	0	55	6.4778	6.54958	-0.07181	4	1
1299	17Aug2020	0	55	8.5167	6.54958	1.96708	7	1
1299	16Nov2020	0	55	7.5063	6.54958	0.95667	7	1
1309	01Jun2020	0	30	5.7694	5.76944	0	4	0
1311	28May2020	0	33	6.7472	6.53241	0.21481	6	1
1311	27Jun2020	0	33	6.7	6.53241	0.16759	3	1
1311	26Jul2020	0	33	6.15	6.53241	-0.38241	3	1
1324	28May2020	1	62	6.37	6.85954	-0.48954	5	1
1324	27Jun2020	1	62	6.0944	6.85954	-0.7651	0	1
1324	30Jul2020	1	62	6.8803	6.85954	0.02076	0	1
1324	26Aug2020	1	62	6.4556	6.85954	-0.40399	0	1
1324	26Sep2020	1	62	7.3308	6.85954	0.47123	0	1
1324	24Oct2020	1	62	7.319	6.85954	0.45951	0	1
1324	26Nov2020	1	62	7.5667	6.85954	0.70713	0	1
1335	03Jun2020	0	24	8.8958	8.48274	0.4131	5	1
1335	06Jul2020	0	24	7.919	8.48274	-0.56369	4	1
1335	03Aug2020	0	24	8.6333	8.48274	0.1506	13	1
1337	05Jun2020	0	65	6.369	4.64143	1.72762	0	0
1337	05Jul2020	0	65	6.45	4.64143	1.80857	0	0
1337	04Aug2020	0	65	4.38	4.64143	-0.26143	0	0
1337	04Sep2020	0	65	1.3667	4.64143	-3.27476	0	0
1463	05Jun2020	0	53	8.5667	4.89659	3.67008	5	1
1463	06Jul2020	0	53	8.2864	4.89659	3.38977	4	1
1463	08Aug2020	0	53	1.3667	4.89659	-3.52992	3	1
1463	06Sep2020	0	53	1.3667	4.89659	-3.52992	1	1
1475	04Jun2020	1	35	7.3767	6.35416	1.02251	1	0
1475	04Jul2020	1	35	7.2202	6.35416	0.86608	0	0
1475	05Aug2020	1	35	7.4917	6.35416	1.13751	1	0
1475	03Sep2020	1	35	6.6845	6.35416	0.33037	0	0
1475	08Oct2020	1	35	4.9519	6.35416	-1.40231	0	0
1475	07Nov2020	1	35	4.4	6.35416	-1.95416	0	0
1482	10Jun2020	1	23	6.3167	8.06841	-1.75175	0	0
1482	10Jul2020	1	23	7.7806	8.06841	-0.28786	0	0
1482	12Aug2020	1	23	9.1288	8.06841	1.06037	0	0
1482	08Sep2020	1	23	8.6136	8.06841	0.54522	3	0
1482	08Oct2020	1	23	8.05	8.06841	-0.01841	0	0
1482	08Nov2020	1	23	8.5208	8.06841	0.45242	0	0
1528	01Jul2020	1	43	7.3733	7.6169	-0.24357	5	1
1528	02Aug2020	1	43	7.9726	7.6169	0.35571	8	1
1528	03Sep2020	1	43	7.5048	7.6169	-0.11214	9	1
1555	07Jul2020	0	39	6.8467	6.44217	0.4045	5	1
1555	06Aug2020	0	39	7.269	6.44217	0.82688	1	1
1555	05Sep2020	0	39	6.1333	6.44217	-0.30884	2	1
1555	05Oct2020	0	39	6.0472	6.44217	-0.39495	2	1
1555	10Nov2020	0	39	5.9146	6.44217	-0.52759	4	1
1556	01Sep2020	0	25	1.3667	5.78778	-4.42111	0	1
1556	01Oct2020	0	25	7.15	5.78778	1.36222	2	1
1556	04Nov2020	0	25	8.8467	5.78778	3.05889	7	1
1591	10Jul2020	0	86	2	2.41148	-0.41148	7	1
1591	10Aug2020	0	86	2.8111	2.41148	0.39963	6	1
1591	07Sep2020	0	86	3.3417	2.41148	0.93019	6	1
1591	07Oct2020	0	86	1.725	2.41148	-0.68648	5	1
1591	07Nov2020	0	86	2.1796	2.41148	-0.23185	1	1
1600	14Jul2020	0	28	5.4524	5.45238	0	4	0
1604	21Jul2020	1	67	6.1556	6.05308	0.10248	2	1
1604	19Aug2020	1	67	6.5646	6.05308	0.51151	5	1
1604	19Sep2020	1	67	6.2	6.05308	0.14692	1	1
1604	18Oct2020	1	67	5.8464	6.05308	-0.20665	2	1
1604	16Nov2020	1	67	5.4988	6.05308	-0.55427	5	1
1629	21Jul2020	0	26	4.0067	4.29931	-0.29265	3	0
1629	20Aug2020	0	26	4.1917	4.29931	-0.10765	0	0
1629	19Sep2020	0	26	4.4194	4.29931	0.12013	1	0
1629	19Oct2020	0	26	4.4909	4.29931	0.1916	2	0
1629	18Nov2020	0	26	4.3879	4.29931	0.08857	0	0
1786	28Jul2020	1	44	6.6944	6.87222	-0.17778	1	0
1786	24Nov2020	1	44	7.05	6.87222	0.17778	0	0
1808	21Jul2020	0	75	7.7083	8.09885	-0.39052	0	0
1808	20Aug2020	0	75	8.4788	8.09885	0.37994	2	0
1808	19Sep2020	0	75	8.2845	8.09885	0.18567	1	0
1808	19Oct2020	0	75	7.7667	8.09885	-0.33219	0	0
1808	18Nov2020	0	75	8.256	8.09885	0.1571	1	0
1813	21Jul2020	0	33	8.4733	8.25495	0.21838	2	0
1813	20Aug2020	0	33	8.0133	8.25495	-0.24162	1	0
1813	20Sep2020	0	33	8.3798	8.25495	0.12481	1	0
1813	19Oct2020	0	33	7.769	8.25495	-0.4859	2	0
1813	18Nov2020	0	33	8.6393	8.25495	0.38433	2	0
1840	28Jul2020	0	26	8.3278	8.20079	0.12698	12	1
1840	27Aug2020	0	26	8.25	8.20079	0.04921	6	1
1840	26Sep2020	0	26	8.2214	8.20079	0.02063	7	1
1840	26Oct2020	0	26	8.1452	8.20079	-0.05556	7	1
1840	25Nov2020	0	26	8.0595	8.20079	-0.14127	7	1
1848	31Jul2020	1	71	8.5833	8.49012	0.09321	2	0
1848	30Aug2020	1	71	8.8	8.49012	0.30988	2	0
1848	29Sep2020	1	71	8.6226	8.49012	0.1325	2	0
1848	29Oct2020	1	71	7.8806	8.49012	-0.60957	2	0
1848	28Nov2020	1	71	8.5641	8.49012	0.07398	2	0
;
Run;
data PA_MH; set PA_MH; format date date9.;run;

I examined linear and quadratic effects of Light_Phys_Act_Within and Light_Phys_Act_Between each interacting with Has_Depr_or_Anxiety on the outcome Depression_Score, adjusting for gender and age. Here is the code for the model:

 

Proc mixed data= PA_MH NOCLPRINT NOITPRINT COVTEST METHOD=ML namelen=70 Plots=none; 
model Depression_Score=Light_Phys_Act_Within 
Light_Phys_Act_Within*Light_Phys_Act_Within 
Light_Phys_Act_Between Light_Phys_Act_Between*Light_Phys_Act_Between Light_Phys_Act_Within*Has_Depr_or_Anxiety Light_Phys_Act_Within*Light_Phys_Act_Within*Has_Depr_or_Anxiety Light_Phys_Act_Between*Has_Depr_or_Anxiety Light_Phys_Act_Between*Light_Phys_Act_Between*Has_Depr_or_Anxiety Has_Depr_or_Anxiety
gender age / SOLUTION CL ddfm=bw; store LPA_dep; RANDOM Intercept / TYPE=AR(1) Subject=subject; Title 'LPA predicting depression score by dep/anx status';run;title;run; ods output fitplot = Fit_LPA_dep; proc plm source=LPA_dep; effectplot fit(x=Light_Phys_Act_Within);run; proc sgplot data=fit_LPA_dep noautolegend; series x = _XCONT1 y = _PREDICTED / lineattrs=(color=BLACK pattern=SOLID thickness=3); band X=_XCONT1 lower= _lclm upper= _uclm / fillattrs=(color=BLACK transparency=.8); xaxis values =(-2 to 2 by 1) label='LPA (difference from mean; hrs)' LABELATTRS=(size=13) VALUEATTRS=(size=13); yaxis grid values=(1 to 6 by 1) label='Depression (score)' LABELATTRS=(size=13) VALUEATTRS=(size=13) GRIDATTRS=(color=GrayCA thickness=.0mm); run;

Here is a plot I have produced that depicts the main effect of Light_Phys_Act_Within on Depression_Score:

 

SGPlot.png

This graph depicts the effect of Light_Phys_Act_Within at the mean of Has_Depr_or_Anxiety. However, I need to depict the effect at three levels, with three lines: One line for the effect at the mean of Has_Depr_or_Anxiety; one for those without depression/anxiety (Has_Depr_or_Anxiety=0); and one for those with depression/anxiety (Has_Depr_or_Anxiety=1). I also need associated confidence intervals and while adjusting for gender and age (as in the model). The confidence intervals will be overlapping, so they will need to be distinguishable from one another (perhaps the line for Has_Depr_or_Anxiety=0 could be dotted with the confidence interval limits being dotted; the line at the mean of Has_Depr_or_Anxiety can be solid with its confidence interval limits being solid; and the line for Has_Depr_or_Anxiety=1 can be dashed with the confidence interval limits being dashed).
 
Can anyone assist? Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Do you want to do something like this:


%macro Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=0 1);

Proc mixed

data= PA_MH(where=(Has_Depr_or_Anxiety in (&Has_Depr_or_Anxiety.))) /* WHERE condition */

NOCLPRINT NOITPRINT COVTEST METHOD=ML namelen=70 Plots=none; 
model Depression_Score=Light_Phys_Act_Within 
Light_Phys_Act_Within*Light_Phys_Act_Within Light_Phys_Act_Between 
Light_Phys_Act_Between*Light_Phys_Act_Between 
Light_Phys_Act_Within*Has_Depr_or_Anxiety 
Light_Phys_Act_Within*Light_Phys_Act_Within*Has_Depr_or_Anxiety 
Light_Phys_Act_Between*Has_Depr_or_Anxiety 
Light_Phys_Act_Between*Light_Phys_Act_Between*Has_Depr_or_Anxiety 
Has_Depr_or_Anxiety gender 
age / 
SOLUTION CL ddfm=bw; 
store LPA_dep; 
RANDOM Intercept / TYPE=AR(1) Subject=subject; 
Title 'LPA predicting depression score by dep/anx status';
run;
title;
run; 

ods output fitplot = Fit_LPA_dep%sysfunc(compress(&Has_Depr_or_Anxiety.)); 

proc plm source=LPA_dep; 
effectplot fit(x=Light_Phys_Act_Within);
run;

%mend Has_Depr_or_Anxiety;

%Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=0 1)
%Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=0)
%Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=1)


data all;
  set Fit_LPA_dep01 Fit_LPA_dep0 Fit_LPA_dep1 indsname=i;
  group = scan(i,-1, "_");
run;

data myattrmap;
  length linecolor fillpatterns $ 20 value $ 20;
  input id $ value $ linecolor $ fillpatterns $ FILLTRANSPARENCY;
  fillcolor=linecolor;
  LINETHICKNESS=3;
  output;
datalines;
myid DEP01 gold X1 0.8
myid DEP0  green L1 0.9
myid DEP1  red R1 0.9
;
run;
proc print;
run;


proc sgplot data=all noautolegend dattrmap=myattrmap; 
 band X=_XCONT1 lower= _lclm upper= _uclm / group=group attrid=myid;
 series x = _XCONT1 y = _PREDICTED / group=group attrid=myid;
 xaxis values =(-2 to 2 by 1) label='LPA (difference from mean; hrs)' LABELATTRS=(size=13) VALUEATTRS=(size=13);
 yaxis grid values=(0 to 6 by 1) label='Depression (score)' LABELATTRS=(size=13) VALUEATTRS=(size=13) GRIDATTRS=(color=GrayCA thickness=.0mm);
run;               

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

2 REPLIES 2
yabwon
Onyx | Level 15

Do you want to do something like this:


%macro Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=0 1);

Proc mixed

data= PA_MH(where=(Has_Depr_or_Anxiety in (&Has_Depr_or_Anxiety.))) /* WHERE condition */

NOCLPRINT NOITPRINT COVTEST METHOD=ML namelen=70 Plots=none; 
model Depression_Score=Light_Phys_Act_Within 
Light_Phys_Act_Within*Light_Phys_Act_Within Light_Phys_Act_Between 
Light_Phys_Act_Between*Light_Phys_Act_Between 
Light_Phys_Act_Within*Has_Depr_or_Anxiety 
Light_Phys_Act_Within*Light_Phys_Act_Within*Has_Depr_or_Anxiety 
Light_Phys_Act_Between*Has_Depr_or_Anxiety 
Light_Phys_Act_Between*Light_Phys_Act_Between*Has_Depr_or_Anxiety 
Has_Depr_or_Anxiety gender 
age / 
SOLUTION CL ddfm=bw; 
store LPA_dep; 
RANDOM Intercept / TYPE=AR(1) Subject=subject; 
Title 'LPA predicting depression score by dep/anx status';
run;
title;
run; 

ods output fitplot = Fit_LPA_dep%sysfunc(compress(&Has_Depr_or_Anxiety.)); 

proc plm source=LPA_dep; 
effectplot fit(x=Light_Phys_Act_Within);
run;

%mend Has_Depr_or_Anxiety;

%Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=0 1)
%Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=0)
%Has_Depr_or_Anxiety(Has_Depr_or_Anxiety=1)


data all;
  set Fit_LPA_dep01 Fit_LPA_dep0 Fit_LPA_dep1 indsname=i;
  group = scan(i,-1, "_");
run;

data myattrmap;
  length linecolor fillpatterns $ 20 value $ 20;
  input id $ value $ linecolor $ fillpatterns $ FILLTRANSPARENCY;
  fillcolor=linecolor;
  LINETHICKNESS=3;
  output;
datalines;
myid DEP01 gold X1 0.8
myid DEP0  green L1 0.9
myid DEP1  red R1 0.9
;
run;
proc print;
run;


proc sgplot data=all noautolegend dattrmap=myattrmap; 
 band X=_XCONT1 lower= _lclm upper= _uclm / group=group attrid=myid;
 series x = _XCONT1 y = _PREDICTED / group=group attrid=myid;
 xaxis values =(-2 to 2 by 1) label='LPA (difference from mean; hrs)' LABELATTRS=(size=13) VALUEATTRS=(size=13);
 yaxis grid values=(0 to 6 by 1) label='Depression (score)' LABELATTRS=(size=13) VALUEATTRS=(size=13) GRIDATTRS=(color=GrayCA thickness=.0mm);
run;               

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



confooseddesi89
Quartz | Level 8

Excellent! This worked perfectly.

 

To obtain the dashed/dotted lines instead of colors, and to get a legend, here is my modified code for the data myattrmap and proc sgplot:

data myattrmap;
length linecolor fillpatterns $ 20 value $ 20;
input id $ value $ linecolor $ fillpatterns $ FILLTRANSPARENCY linepattern $;
 fillcolor=linecolor;
LINETHICKNESS=3; 
output;
datalines;
myid DEP01 black X1 0.8 Solid
myid DEP0  black L1 0.9 Dot
myid DEP1  black R1 0.9 Dash
;
run;
proc print;
run;

proc sgplot data=all dattrmap=myattrmap; 
 band X=_XCONT1 lower= _lclm upper= _uclm / group=group attrid=myid;
 series x = _XCONT1 y = _PREDICTED / group=group attrid=myid;
 xaxis values =(-2 to 2 by 1)  label='LPA (difference from mean; hrs) ' LABELATTRS=(size=13 Weight=Bold) VALUEATTRS=(size=13);
legenditem type=LINE name='DEP01' /label='Overall' lineattrs=(pattern=Solid);
legenditem type=LINE name='DEP0' /label='No report of D/A' lineattrs=(pattern=Dot);
legenditem type=LINE name='DEP1' /label='>=1 report of D/A' lineattrs=(pattern=Dash);
keylegend 'DEP01' 'DEP0' 'DEP1' / title='Mental health status' VALUEATTRS=(size=12) TITLEATTRS=(Size=14 Weight=Bold)
location=outside position=top; 
yaxis grid values=(0 to 10 by 1) label='Depression (score)' LABELATTRS=(size=13 Weight=Bold) 
VALUEATTRS=(size=13) GRIDATTRS=(color=GrayCA thickness=.0mm);run;

sas-innovate-2024.png

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 254 views
  • 1 like
  • 2 in conversation