Create variable that uses value of another variable to determine which other variable from which to take value

Advertisements Say I have these data: clear all input id var1 var2 var3 key 1 23 45 8 2 2 11 7 99 3 3 29 22 1 1 4 5 61 5 2 end How can I create another variable called want that uses the key variable as a key to identify which variable… Read More Create variable that uses value of another variable to determine which other variable from which to take value

Create new variable x by selecting the value of a cell in a row conditional on the variable name containing the value of a variable z

Advertisements I have a dataset of individuals. Each individual is observed across different years and countries. I have two independent variables x2002 and x2010 (see Dataex example: Before). These contain the values of a variable X for each year for a specific country. For example, all individuals observed in 2002 in France have a value… Read More Create new variable x by selecting the value of a cell in a row conditional on the variable name containing the value of a variable z

Using cross-sectional data for OLS/logit models

Advertisements I have a cross-sectional dataset with the data example below, where the variable (id) refers to each individual in the df and rows represent the different number of Reddit posts written by each username, which vary across individuals. My goal is to use OLS regression to predict average sentiment, based on individual-level covariates which… Read More Using cross-sectional data for OLS/logit models

Add days to datetime

Advertisements I would like to add 24 hours or 1 day to my timedate variable in Stata. read_date Desired_date 2009-01-01 14:00:00 2009-01-02 14:00:00 I formatted my read_date with format read_date %tcCCYY-NN-DD_HH:MM:SS which worked without errors. I have been trying to add days by adding 86400 seconds as: replace Desired_date = Desired_date+86400 It executes without errors… Read More Add days to datetime