Hello everyone,
I am working with a panel dataset consisting of firm-year observations spanning from 2018 to 2021. Within this dataset, I have several categorical variables (e.g., question1, question2, etc.) that vary in their responses ("Y", "N", missing) across different years. My goal is to create tables for each of these variables, displaying the evolution of these responses over time. I believe providing the data structure I'm working with and outlining the desired table will clarify the issue at hand.
Here's a glimpse of the dataset structure:
In this dataset, the variable question1_prec represents the response to question1 in 2018, while question1_ld1c denotes the response to the same question in 2019, and so forth. I am using the lead versions of these variables to facilitate tabulation, aiming to use the condition if year==2018.
The table I am aiming to construct looks like this:
Essentially, I aim to visualize the changes in responses for question1 over time. I'm using question1_prec (i.e., the 2018 response) as the baseline and seeking to showcase what happened to firms that responded "N" in 2018: did their responses change to "Y" or missing, were they dropped from the dataset, or did they maintain the "N" response in 2019, 2020, and 2021? What about firms that responded "Y" in 2018? And so on.
To elucidate further, I am essentially seeking a similar outcome as the following code: tab2 question1_prec question1_ld1c; tab2 question1_prec question1_ld2c; tab2 question1_prec question1_ld3c, but merged into a single comprehensive table.
Additionally, I would greatly appreciate any advice on exporting such a table. Until now, I have been using asdoc, but I'm uncertain if it can support the solutions provided.
Despite potentially seeming trivial, the solutions I've attempted so far have not yielded the desired results.
Thank you sincerely for your assistance!
Claudio
I am working with a panel dataset consisting of firm-year observations spanning from 2018 to 2021. Within this dataset, I have several categorical variables (e.g., question1, question2, etc.) that vary in their responses ("Y", "N", missing) across different years. My goal is to create tables for each of these variables, displaying the evolution of these responses over time. I believe providing the data structure I'm working with and outlining the desired table will clarify the issue at hand.
Here's a glimpse of the dataset structure:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float individual_id double year str1(question1_prec question1_ld1c question1_ld2c question1_ld3c) 1 2018 "Y" "" "" "" 2 2018 "Y" "N" "Y" "Y" 3 2018 "" "Y" "Y" "Y" 4 2018 "Y" "Y" "Y" "Y" 5 2018 "N" "N" "N" "N" 8 2018 "Y" "Y" "Y" "Y" 9 2018 "" "Y" "Y" "Y" 10 2018 "" "" "" "" 11 2018 "N" "N" "" "" 12 2018 "" "N" "N" "N" 13 2018 "N" "N" "N" "Y" 14 2018 "Y" "N" "N" "Y" end
The table I am aiming to construct looks like this:
question1_ld1c | question1_ld2c | question1_ld3c | total | ||||||||||
question1_pre | N | Y | . | dropped | N | Y | . | dropped | N | Y | . | dropped | |
N | 20 | 40 | 20 | 20 | 20 | 20 | 20 | 40 | 20 | 10 | 10 | 60 | 100 |
Y | 0 | 50 | 5 | 5 | 5 | 40 | 5 | 10 | 5 | 25 | 10 | 20 | 60 |
. | 0 | 0 | 40 | 0 | 0 | 5 | 35 | 0 | 0 | 10 | 10 | 20 | 40 |
200 |
Essentially, I aim to visualize the changes in responses for question1 over time. I'm using question1_prec (i.e., the 2018 response) as the baseline and seeking to showcase what happened to firms that responded "N" in 2018: did their responses change to "Y" or missing, were they dropped from the dataset, or did they maintain the "N" response in 2019, 2020, and 2021? What about firms that responded "Y" in 2018? And so on.
To elucidate further, I am essentially seeking a similar outcome as the following code: tab2 question1_prec question1_ld1c; tab2 question1_prec question1_ld2c; tab2 question1_prec question1_ld3c, but merged into a single comprehensive table.
Additionally, I would greatly appreciate any advice on exporting such a table. Until now, I have been using asdoc, but I'm uncertain if it can support the solutions provided.
Despite potentially seeming trivial, the solutions I've attempted so far have not yielded the desired results.
Thank you sincerely for your assistance!
Claudio
Comment