-
Generate Sample Pre- and Post-Intervention Survey Data using Python on the TSSFL Technology Stack
-
Test and Analyze Survey Datasets with the Survey Insights Generator on TSSFL Technology Stack
Hi everyone,
I’d like to share a simple Python script that generates mock data for pre- and post-intervention surveys. This can be useful for anyone working on research, program evaluation, or simulations where realistic survey data is needed for testing or demonstration purposes.
- Number of Respondents: 100
- Number of Questions: 16
- Response Options (Likert Scale):
- Strongly Disagree
- Disagree
- Somewhat Agree
- Agree
- Strongly Agree
The script generates four files:
- pre_survey.xlsx
- post_survey.xlsx
- pre_survey.csv
- post_survey.csv
Python Script
- import pandas as pd
- import numpy as np
- #Define parameters
- num_questions = 16
- num_respondents = 100
- response_options = ["Strongly Disagree", "Disagree", "Somewhat Agree", "Agree", "Strongly Agree"]
- # Generate column names for questions
- question_columns = [f"Q{i+1}" for i in range(num_questions)]
- # Generate random responses for pre and post surveys
- pre_survey_data = pd.DataFrame({
- question: np.random.choice(response_options, size=num_respondents)
- for question in question_columns
- })
- post_survey_data = pd.DataFrame({
- question: np.random.choice(response_options, size=num_respondents)
- for question in question_columns
- })
- # Save to Excel and CSV files
- pre_survey_data.to_excel("pre_survey.xlsx", index=False)
- post_survey_data.to_excel("post_survey.xlsx", index=False)
- pre_survey_data.to_csv("pre_survey.csv", index=False)
- post_survey_data.to_csv("post_survey.csv", index=False)
Feel free to adapt the script to your specific use case - such as changing the number of respondents or using a custom set of questions.
You can generate the dataset by running the Python code at AI-Assisted Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2
And test the datasets with our app - Survey Insights Generator.
Let me know if you have any questions or suggestions!