Re: [R] Creating a before-and-after variable in R

2019-10-03 Thread Faradj Koliev
(a), function(i) { b <- v[a$country_code[i]]; > a$year[i] - ifelse(is.na(b),d,b)}) > > Best, > Eric > > > > > > On Thu, Oct 3, 2019 at 5:19 PM Faradj Koliev wrote: > Hi, > > I was thinking that it could simply show the negative counts. For ex: if

Re: [R] Creating a before-and-after variable in R

2019-10-03 Thread Faradj Koliev
rev Eric Berger : > > Hi Faradj, > What should the treatment variable be in those cases? If you want to set it > to a constant y (such as y=0), you can add something like > > y <- 0 > a$treatment[ is.na(a$treatment) ] <- y > > HTH, > Eric > > > On Thu

Re: [R] Creating a before-and-after variable in R

2019-10-03 Thread Faradj Koliev
a$treatment <- sapply( 1:nrow(a), function(i) { a$year[i] - > v[a$country_code[i]]}) > > HTH, > Eric > > > On Thu, Oct 3, 2019 at 3:36 PM Faradj Koliev wrote: > Dear Michael Dewey, > > Thanks for reaching out about this. I trying again, now with plain text, a

Re: [R] Creating a before-and-after variable in R

2019-10-03 Thread Faradj Koliev
= c(NA, -722L)) > 3 okt. 2019 kl. 14:24 skrev Michael Dewey : > > Dear Faradj > > I am afraid your post is unreadable since this is a plain text list and you > sent in HTML. > > Michael > > On 03/10/2019 12:17, Faradj Koliev wrote: >> Dear R-users, >>

[R] Creating a before-and-after variable in R

2019-10-03 Thread Faradj Koliev
Dear R-users, I need an urgent help with the following: I have a country-year data covering the period 1982 - 2013. I want to assess how the variable X (a certain policy) affects the Y variable. The X variable is =1 when a country introduces that policy in a specific year, otherwise =0. What

Re: [R] Creating a conditional lag variable in R

2019-07-27 Thread Faradj Koliev
%>% mutate( idx = +( (lag(X1) == 0 & X1 == 1) | row_number() == 1 & X1 == 1), X1_pre4 = check_pre(idx, 4), X1_pre5 = check_pre(idx, 5), idx = NULL ) > On 27 Jul 2019, at 10:45, Faradj Koliev wrote: > > Peter Dalgaard, > > Thanks for this. >

Re: [R] Creating a conditional lag variable in R

2019-07-27 Thread Faradj Koliev
reement. Then X1_pre4 should be as.integer(tt <=4 > & tt > 0) > > -pd > >> On 27 Jul 2019, at 09:13 , Faradj Koliev wrote: >> >> Re-post, now in *plain text*. >> >> >> >> Dear R-users, >> >> I’ve a rather comp

Re: [R] Creating a conditional lag variable in R

2019-07-27 Thread Faradj Koliev
king things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Fri, Jul 26, 2019 at 12:25 PM Faradj Koliev wrote: > Dear R-users, > > I’ve a rather complicated task to do and need all the help I can get. > > I have data i

[R] Creating a conditional lag variable in R

2019-07-26 Thread Faradj Koliev
Dear R-users, I’ve a rather complicated task to do and need all the help I can get. I have data indicating whether a country has signed an agreement or not (1=yes and 0=otherwise). I want to simply create variable that would capture the years before the agreement is signed. The aim is to see

Re: [R] Capturing positive and negative changes using R

2019-07-21 Thread Faradj Koliev
da,2,2 > >2002,Canada,2,2 > >2003,Canada,1,2 > >2004,Canada,2,0.5 > >2005,Canada,1,0.5 > >2006,Canada,0,0.5 > >2007,Canada,1,0.5 > >2008,Canada,0,0.5 > >2009,Canada,1,0.5 > >2010,Canada,1,0.5 > >2011,Canada,0,1", > >h

[R] Capturing positive and negative changes using R

2019-07-20 Thread Faradj Koliev
Dear R-users, I have a country-year data for 180 countries from 1970 to 2010. I’m interested in capturing positive and negative changes in some of the variables. Some of these variables are continuous (0,25, 0,33, 1, 1,5 etc) others are ordered (0,1, 2). To do this, I use this code data$X1_c

Re: [R] How to generate a conditional dummy in R?

2018-05-29 Thread Faradj Koliev
1 0 > [75] 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 >> fkdf$X > [1] 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0 > [38] 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 > [75] 1 0 0 0 1 0 0

[R] How to generate a conditional dummy in R?

2018-05-28 Thread Faradj Koliev
Hi everyone, I am trying to generate a conditional dummy variable ”X" with the following rules set X=1 if Y is =1, two years prior to the NA. [0,0,NA]. For example, if the pattern for Y is 0,0,NA then the X variable is =0 for all the two years prior to the NA. If the pattern for Y is 0,1

Re: [R] Log plus one transformation in R

2016-12-12 Thread Faradj Koliev
t;> E.g., >>>> options(digits=16) >>>> base::log1p(1e-14) >>> [1] 9.95e-15 >>>> base::log1p(1e-14) - base::log(1+1e-14) >>> [1] 7.992778373591124e-18 >>>> as.numeric(log(Rmpfr::mpfr(1,precBits=1000) + Rmpfr::mpfr(1e

[R] Log plus one transformation in R

2016-12-12 Thread Faradj Koliev
Hi all, How do I perform log(x+1) in R? log1p_trans() from the package ”scales" doesn’t seem to work for me. Best, Faradj __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do re

[R] How to plot predicted probabilities with 95% CIs

2016-10-03 Thread Faradj Koliev
Dear all, I need a little help with plotting predicted probabilities (values). Consider the following example ** data(”mtcars”) mfit = lm(mpg ~ vs + disp + cyl, data=mtcars) newcar=data.frame(vs=c(0,1), disp=230, cyl=6.188) Pmodel<–predict(mfit, newcar) ** I want to plot the effect of ”vs

Re: [R] Hickman models with two binary dependent variables in R

2016-08-27 Thread Faradj Koliev
; >> See in line >> >>> -Original Message- >>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Faradj >>> Koliev >>> Sent: Thursday, August 25, 2016 12:32 PM >>> To: r-help@r-project.org >>> Subject: [R] Hickma

[R] Hickman models with two binary dependent variables in R

2016-08-25 Thread Faradj Koliev
Hi everyone, How do I run Heckman models in R with two binary dependent variables? sampleSelection package in R works with standard heckman models ( binary DV for the selection equation and continuous DV for the outcome equation). In my case dependent variables are both binary (actually order

[R] How to create marginal effects tables in R?

2016-08-08 Thread Faradj Koliev
Hi everyone, I have three ordered regression models where the ordered dependent variable ranges from 0 to 2. What I want to do is create marginal effects tables (not a plot) at each level (0, 1, and 2) for all three models. So, three tables with each showing the marginal effects at level 0, 1,

Re: [R] Likelihood ratio test in porl (MASS)

2016-07-27 Thread Faradj Koliev
tat. Pr(Chi) 1 2121 1763.999 2 2120 1732.787 1 vs 2 1 31.21204 2.313266e-08 And both seems to reject the null hypothesis. Thanks again! Best, Faradj > 27 jul 2016 kl. 13:35 skrev Fox, John : > > Dear Faradj Koliev, > >

[R] Likelihood ratio test in porl (MASS)

2016-07-27 Thread Faradj Koliev
Dear all, A quick question: Let’s say I have a full and a restricted model that looks something like this: Full<- polr(Y ~ X1+X2+X3+X4, data=data, Hess = TRUE, method="logistic”) # ordered logistic regression Restricted<- polr(Y ~ X1+X2+X3, data=data, Hess = TRUE, method="logistic”) # or

Re: [R] How to plot marginal effects (MEM) in R?

2016-07-21 Thread Faradj Koliev
Dear David Winsemius, Thank you! The sample make no sense, I know. The real data is too big. So, I only want to understand how to plot marginal effects, to visualize them in a proper way. Best, > 22 juli 2016 kl. 08:35 skrev David Winsemius : > >> >> On Jul 21, 2016,

[R] How to plot marginal effects (MEM) in R?

2016-07-21 Thread Faradj Koliev
Dear all, I have two logistic regression models: • model <- glm(Y ~ X1+X2+X3+X4, data = data, family = "binomial") • modelInteraction <- glm(Y ~ X1+X2+X3+X4+X1*X4, data = data, family = "binomial") To calculate the marginal effects (MEM approach) for these models, I used the `mfx` p

[R] How to generate “aggregated” time lags?

2016-07-14 Thread Faradj Koliev
Dear all, I hope you’re enjoying your summer! I've been asked to "aggregate" my time lags from simple 1 year time lag to 1-3 year time lag. This could be done --I've been told --by simply taking the sum or mean of time lag 1,2, and 3. I need your help here. How can I generate this "aggrega

Re: [R] Logistic regression and robust standard errors

2016-07-01 Thread Faradj Koliev
ng now? > 1 jul 2016 kl. 14:57 skrev Achim Zeileis : > > On Fri, 1 Jul 2016, Faradj Koliev wrote: > >> Dear all, >> >> I use ?polr? command (library: MASS) to estimate an ordered logistic >> regression. >> >> My model: summary( model<-

[R] Logistic regression and robust standard errors

2016-07-01 Thread Faradj Koliev
Dear all, I use ”polr” command (library: MASS) to estimate an ordered logistic regression. My model: summary( model<- polr(y ~ x1+x2+x3+x4+x1*x2 ,data=mydata, Hess = TRUE)) But how do I get robust clustered standard errors? I’’ve tried coeftest(resA, vcov=vcovHC(resA, cluster=lipton$ID)

[R] How to create these variables in R?

2016-06-28 Thread Faradj Koliev
Dear all, Let’s say that I have a dataset that looks something like this: Subject YearA A 19901 A 19911 A 19921 A 19931 A 19940 A 19950 B 19901 B 19910 B 19921 B 19

[R] Robust clustered errors for probit ordinal regression analysis

2016-04-28 Thread Faradj Koliev
Dear all, I’ll need your help with obtaining robust clustered errors. I use polr command in MASS package m<–porl(y~x1+x2,data=mydata, method=probit). In the rms package, this is as simple as: clusterSE<–robcov(m, mydata$id). Is it possible to do something similar for polr object as well? Thank

[R] Predicting probabilities in ordinal probit analysis in R

2016-04-26 Thread Faradj Koliev
Dear all, I have two questions that are almost completely related to how to do things in R. I am running an ordinal probit regression analysis in R. The dependent variable has three levels (0=no action; 1=warning; 2=sanction). I use the lrm command in the rms package: print( res1<- lrm(Y ~ x

[R] Online courses in Event History / Survival analysis with R

2015-05-24 Thread Faradj Koliev
Dear all, I am looking for some online courses – paid or free – in survival analysis with R. Perhaps you can recommend some interesting online courses? Best, Faradj Koliev __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https

[R] Need HELP: how find and use a csv file?

2012-07-10 Thread Faradj Koliev
Hey, I am having some problems with importing a csv file into R and then saving it for analyzing. I got a csv file ( skater.csv) which i could read by typing: read.csv(file="/Users/kama/Desktop/skatter.csv", header=TRUE, sep=";") However, when i enter:skatter.csv<-read.csv("skatter.c